How to Identify current locale in a site - php

I am using OJS cms, which is a Open Journals System.
I want to add some parts to registration page.
In registration page I want to know what language/locale is set, in order to put some more fields if specific language/locale is set.
I want current locale of the site. How can I recognize what locale is set by user by if statement? I searched stackoverflow but and found some result but non of them were helpful for me.
By the way, this cms is written by PHP. For more inforemation click here.

The best way is to use {$currentLocale}. It tells us what language the website is set in.

Related

How to update the content of a website using the website itself?

Is it possible to update the content of a website (add Item, remove Item, update Infos, etc...) directly from the webpage?
For example, you have a webpage and you make a new page in it, that only the admin can access. That page should contain some options that allow the admin to change/update contents on the actual website(what people can see) easily.
(Without the admin having to write new HTML or PHP code...)
I heard something about Joomla or Wordpress but I don't really know how they work.
Thank you.
Basicaly, joomla has some fonctionnalities to edit content by the frontoffice. Of course, the user need to be logged and access levels need to be well managed. You should to try it with a basic installation and see if it's coherent with respect to that you looking for.

LARAVEL Redirect user to same page they are viewing when language change link is clicked in the web page

I am new to Laravel and the scenario is like this: I have a bilingual site built using laravel and my problem lies in let's say, for example, the user is viewing about us page and he chose to change language of the about us page to french. Now what i want to do is redirect the user to the same page url (about us) page even after language change link is clicked. And my language changing logic is based on setting session variable i.e. if sesssion[$lang]= 1 fetch english content and if 2 fetch french content. My daunting problem lies in capturing the currently active page URL and redirect the user to the same URL after changing the language to french !!!!! And i don't even know is my change language logic standard one or not
An easy way is to use the redirect()->back() method to go back where you were , but i believe a better practice is to define language also through routes example
Route::get('about_us/{lang}','YourController#method_name');
and grouping them by middleware to switch between languages and redirecting to about_us/ar , about_us/en or whatever but you have mentioned that you are using sessions so just
redirect()->back()
after changing language .

Redirect my website joomla

I want to redirect my website in differents languages when detect the country by (GeoIP), actually i have these urls and works well clicking on the flag images.
www.myweb.com/en www.myweb.com/es www.myweb.com/pt
But i dont know how to do it in joomla using the geoip.
I tried with .htacess and the answer of this question
how to redirect domain according to country IP address
and i have the error 500
SOLUTION:
Joomla provides a browser settings in system language plugin, just setting the joomla with this works perfectly!!
This extension does the job: http://extensions.joomla.org/extensions/style-a-design/templating/11173 Note that it's commercial. Your alternative would be download the GeoIP database (it's available for free), and then create a small plugin that does the redirection.
If you want, you can take a look at our post here: http://www.itoctopus.com/how-to-block-a-whole-country-on-your-joomla-website on how to block a country. You will only need to slightly modify the code to make it so that it redirects to another page for a certain country.
Try this,
Create a system plugin for Joomla
PHP functions available for checking visitors country use that identify the location.
redirect according to that.
Hope it helps..

How does Facebook make personal named pages?

Hey guys hope all is good and here's my question: When you click on a Facebook profile the address bar shows the URI named after the account's owner, for example:
Name: John Smith
Facebook URI: facebook.com/john.smith
The question is, how is this achieved to dynamically name a page based on the name of each user. I do not believe Facebook would make a directory named after each user and then add the same html, css, scripts etc in every directory... So if I decided to make a member's page in PHP how would I go about naming it depending on the user's name?
All constructive answers welcome and have a nice day.
If you have used any frameworks before, you'd be familiar with the concept of routing.
I will give you a rough idea which can be reproduced in any framework. There is an assumption that I will make: You have a table which is storing the user's details and it has a field for the custom URL slug.
Now the logic:
Let's say you have a route configured like website.com/user/mr.xyz.
This means that the route for user/query will be set to a controller like User(query).
Now, you check the query value and see if it is present in your database with the customized URL field.
If it matches, then you load that user's profile.
Update
You should see how routes work in Laravel. If you are not aware of frameworks, then you should learn one to understand how these things work.
This is usually acheived through a rewrite module such as apache's mod_rewrite.
This internally changes (rewrites) the url from domain.com/profilename to something like domain.com/profile.php?profile=profilename. You can then access the query parameter using $_GET['profile']. This is actually a feature of apache and not PHP.
The rewrite happens on the server so the browser will still display the friendly url to the user.
Here is a more in-depth article/tutorial.
http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/?search_index=13
Good luck

How to handle current language? Always in URL, or session?

Im planning to add language feature to my site. I can see two ways:
storing language in the url, so always www.mysite.com/en/introduce, www.mysite.com/en/home, or if 1st parameter is missing, just use the default. Its good for bookmark, but very hard to implement to all available links
storing in session. Way much easier, but users may gets confused not seeing the language in the URL.
I would say: session. What would you say? Any experiences?
If you want all your pages to be indexed by search engines, you'll have put the language parameter in the URL.
If you're producing more something like Facebook where a user needs to be logged in to receive content in his personalized language, use sessions.
I would use the first method togetter with a url rewrite engine.
F.e. when using RewriteEngine for Apache you could add this line to your .htaccess:
RewriteRule ^([a-zA-Z][a-zA-Z])/([a-zA-Z]*)$ content.php?culture=$1&content=$2
and even this can work:
RewriteRule ^([a-zA-Z][a-zA-Z])/([a-zA-Z]*)$ $2.php?culture=$1
You want to put your language as part of the url, otherwise google won't be able to index it for different countries. Also, they might think you have two types of content on the same page.
I would store it in session if there's only some parts of content changing as it's easier to implement if you're just changing i.e. contact details for the company based on what country the user is coming from. But as a general rule, give it a separate url either using .htaccess or your routing system.
Regular users don't look at URL and change the parameters from there. Normal users are point and click. Keep the language selection somewhere visible on the page and also in the user settings. This is not something that a user will want to change several times during a visit. We are talking about a setting that you can ask and set on the first visit. Currently I hate the way the google does it using my IP, assuming (wrong) that if I am entering from Norway I definitely speak Norwegian and I can handle finding in Norwegian menus the English version. I do like the way Etsy.com is doing it, they ask you on the first visit what is your preferred language, currency and so on. If you accept them good, but you can change them right there without having to navigate to a menu. In my opinion go for cookies or session instead of polluting the URL.

Categories