Setting:
7 System Lanaguages
An editor page which is entirely German (no language switcher).
However part of the page is a preview screen where the editor ought to see the edited content already translated into the respective System Language.
Is there a way I can give JText::_('TRANSLATE_STRING') a parameter which determines the target language of the translation?
Is there another function which gives easy access to the translation?
Or can I change the current language of the Session programatically?
I am a little lost on the documentations I find online and stuck without the right ideas or terms to research.
JFactory::getLanguage() will get you the current language object (JLanguage instance).
JLanguage::getInstance($lang) can get you the language instance you want. You'll need to specify the language code as parameter. You can then use the instance to translate language resources.
For example:
$lang = JLanguage::getInstance('de-DE');
echo $lang->_('TRANSLATE_STRING');
Would output the german version of 'TRANSLATE_STRING'
Related
I am trying to make a website with both English and Hindi in option just like the website digit.in .
How can I make this happen?
The website is dynamic.please help me .Since i had already created english version of my website.Now I had to work on only Hindi version of it
First step would be to duplicate your content in Hindi(flag it differently in the database(or file system, different directories for each language) ie lang='en' for english, lang='hi' for hindi).
Then, you have 2 options: Use JS to detect the users language settings, and display the correct content based on that:
JavaScript for detecting browser language preference
Or, you can just create a drop down option(or any other type of selector) somewhere on your site that allows them to select their preferred language, and again serve the correct content based on that option.
EDIT*
If you want to do it purely with PHP, you'd have to detect the language setting in the User-Agent string.
Detect Browser Language in PHP
Create a config with language files. In each file create a language folder e.g hindi,arabic,french. Then in your layout reference the files.
I'm trying to force the language swither module not to redirect to the home page if there is no menu item associations in Joomla 2.5.
I would just like to change country code in the current URL.
So that 'my-domain.com/en/menu?view=cat&id=1' translate to: 'my-domain.com/de/menu?view=cat&id=1' and so on ...
I guess I should modify modLanguagesHelper class but do not know how to create a required $language->link to work properly through JRoute.
Any help is appreciated!
Joomla usually does that by default. It seems strange that it doesn't with the approach you have followed.
Although, reading the comments you left, I understand it's not an easy task and you have already built quite a big part of the website, to go back to structure.
If I were you, I would write a small custom module to change the lang=xx or /xx/ in the URL, and redirect the user to the language they want. If you need help on that, feel free to comment below.
As per your question, I would personally go with simple string manipulation. Since you are really familiar with PHP (taking into consideration that you have written your own custom component), it should be a piece of cake for you, to:
Get the current URL
Get the current language tag
Replace the instances of lang=en with lang=de (example languages, you get the point)
Replace the instances of yoursite.com/en/ with yoursite.com/de/
Print the custom links, flags or whatever you are going to use.
It's not the suggested scenario, but you can really make a usable module if you also add:
An option for the administrator to write the language codes to use (to allow for later additions)
And make sure that you get the site name dynamically, and then you may also have a module that could be published in the JED to help others in the same situation like you!
I have a site with texts in 2 languages. How should I go between the pages so that from the point that he clicked to change the language he will see it and the moment he clicks the other language, it will change back?
An option is that when the user clicks the link to change the language I will store it into the session and use it. But I've heard it won't work well with the search engines.
A second option is to pass the language variable through the URL to every page.
Third option is to smartly use the zend extension ability.
(Using PHP + Zend Framework).
SEO is very important to me.
EDIT:
The texts that are in the site(and that are in several languages), are entered by an admin. It works now with languages objects that I've created with the option for the admin to add texts in each of them. So when I'll enter the first page(of which the text can be changed) I'll see it in English and when I click the Russian flag it will display that page(and the others later) in Russian.
Using Zend_Locale or translate won't work for me(I think), and passing through the URL is an option. The question is if it is the best one?
It is best to pass it along as a parameter in the URL, google uses locale=en for this. It would also be ok to store it in the session only if the user is logged into your website and selected a preferred locale or something. That way search engines can index the different locales with different urls, but your users would see pages in whatever locale they have chosen.
Zend Framework provides a pretty solid set of tools for this.
Start with Zend_Locale and Zend_Translate
It ought to be possible to tweak ZF's routing to contain a segment that indicates the locale. So you'd end up something like /:locale/:controller/:action (or similar). Your URLs would then look like http://example.com/en/some-controller/some-action.
Note that there's more than just translation of language. You can also localize the display of numbers, currency, dates, etc.
Come back with more specific questions once you've played with those.
I am trying to implement CI uri identifier plugin - http://codeigniter.com/wiki/URI_Language_Identifier/
I set the code on a base codeignitor setup. The “ingore_lang” is set to “en”. I am using “alt_site_url” to generate alternative language links.
Now with english it is working all good, links are fine.
But when I click on any other language, the next set of alternate language urls is not replacing the abbr to the present link. For eg. if Spanish is selected, on the new page the link to italian language becomes:
mysite/es/it
I have also observed that the alternate language links never show “english” in the list. I assume they are still taking english as current language.
Please help, am I missing something? I applied the code to all specified files as guided.
Thanks
You should remove 'en' from the lang_ignore var, that should add english to alt languages list. Not sure about the es/it part...
Could you post the code of the implementation you used? I'm also using this in my application and it works fine for me.
What is the best way for supporting a multi-language site in smarty template?
I have read http://smarty.incutio.com/?page=SmartyMultilanguageSupport
and http://www.smarty.net/docsv2/fr/language.config.variables.tpl and now I can't make a decision which option I will to use.
Are there other options?
I use a $_get['lang'] to get the language to be used. In the template, for every pages I get 2 ifs, one if EN another if FR and I generate the code accordingly.
The header footer and meta data comes from database and based on the language, the row required by the language will be fetched.
I read language from cookies and set/change it with http request. Based on the languge used, I just change field names (in php) to query from database (including all strings on page - they are stored for each language in different fields - I know that this is not very scalable, but will be enough for this kind of sites). Additionally I set one smarty variable to language code and when needed (rarely, because strings are already localised), I use smarty {if $language ...} structures to change output.
Someone might find this interesting. Basically lang variable to get the current language and loads a file via config_load. Both are basically the same, just that your first link has all the functions needed packed into a small module.
http://www.freesoftwaremagazine.com/articles/creating_multilingual_website_smarty