Multi languages site - php

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.

Related

Joomla language switcher override

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!

Writing a mutiple language website: the webdesigner's (best) options

They are some questions already about this on stackoverflow, but none is really clear about the 'best practice'.
For the content design, what are the options and what is the better option?
Some options I know are using folders: site.com/en/ and site.com/fr/ or redirects site.com/index.php?language=en
An even easier practice is using a new url: en.site.com and fr.site.com
But what if I want to keep site.com/index.php and nothing more ? What are my options for that?
For example, if you change the language on LinkedIn, there's nothing changing in the URL. How do they work there ?
update: in my case the website is a platform, using LAMP stack. Technical advice is also welcome (like how to store/link all the different language files)
You have some options, and each has its own advantages.
If you have a web app, which should not be indexed by search engines, then you are free to do whatever you want. You can keep a language setting in your Session and show strings in the chosen language. This will simplify URLs and management.
However, if you have a standard website which should go into Google, then your options are restricted. If you use the former approach, google will be confused and will index only one language, or, worse, make an ugly mix of the languages. Google does not keep sessions when indexing your page, so if you have two versions of the same page in two different languages, they need to have different URLs. And passing a language as a GET parameter each time is ugly, error prone, and not user friendly.
So you should either have languages as folders (eg. site.com/en/), which is the best options, or use subdomains. This can be a problem, however, because each subdomain is indexed as if it were a separate website, so things like pagerank and site reputation are split among the two.
Here are my recommendations based on multi-languages web sites experience
You can determine the language of the browser in Javascript (see this), which is a good start in having a language that likely fits the user demand
Use utf8 for encoding, everywhere (browser headers, programming, database). The only drawback I know of utf8 is that in some cases, the number of bytes it takes is bigger than another encoding matching more closely a given language (utf8 is opened to any). Big advantage, it covers any language, the ASCII part (bytes < 128) is the same as a western encoding (takes only one byte) ...
Store the user preferences (not in URL).
either in a cookie (+ : user does not have to be logged it on his computer to keep her prefs ; - : when user accesses the page from another computer, the cookie is not present and he/she has to reselect the pref).
or in a session (requires user login to deterime which user is currently using the site)
Regarding the site structure, if you don't store the user preferences, the common /us /fr /jp... solution has advantages: search engines robots will find all languages from root (the page display doesn't depend on user choice). Or you could load only a language dependent Javascript that displays the page immediately (after JS download) in the language of choice, without the need of a page reload / redirect.
You can tell Google what the parameters in the URL mean through Google's Webmaster Tools. So if you use a standard convention like index.php for the main page and a parameter like ?lang=fr for let's say French content in regard to SEO as long as it's a real translation. Likewise when Google.fr crawls the site you would present their users with the French version of the page based on their default setting in their browser. This will increase stickiness on the site and then increase the rank for the selected search terms in French. You can check their default language with this in PHP to make it less heavy on the user's end:
<?php
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
echo $lang;
?>
Then you would simply concatenate the language selected (as an overlay) to the end of the query string (if it's not the default), bypassing the need for storing a cookie. This should also help from a user experience standpoint. It's not as "pretty" but if people aren't typing it in, it's much more user friendly in that:
People can switch languages by changing the variable
People can provide a link to a user in another country and they can be presented with the page in their native language intuitively when PHP checks their language. "Do you want to see this content in French?"
The native language could in theory be translated on the fly with something like the Google Translate Widget or Google Chrome's built-in functionality.
Content is only served on one URI per page meaning you would not have to rewrite several redirects between versions in the event of stale content. As you're not likely translating into both languages at the same time.
From Wikipedia on Chrome:
As of February 2013, according to StatCounter, Google Chrome has a 37%
worldwide usage share of web browsers making it the most widely used
web browser in the world.
As for storing the files, you can make separate tables in the database for each language, enter in the content in the native language, then duplicate that content to the other language's table. Then you could translate that content live on screen if so desired, or allow someone access to your CMS who could translate the content. Both records would have the same ID in the database so the page would be served appropriately when the language was looked up.
Large corporate sites do the handling of the URLs in a couple of ways, they would show french content at http://www.some_website.fr/ and English content at http://www.some_website.com/. Sites like wikipedia use a subdns so http://fr.wikipedia.org/ and http://en.wikipedia.org.
HTML5 supports the lang='fr' approach to declaring content on screen.
I don't know what's your situation but, imho, you shouldn't use new urls.. it would only be a useless waste of resources (all kinds of resources).. If your website's client-side is javascript-based, you could use libraries like i18next, which gives you great support in localizations.. That's a valid alternative if you agree leaving the localization at you application's client-side.
For server-side localization in php, i wouldn't be of any help..

Website translation onload

I have a dating site which is currently in English language.
As per client requirement he told me to convert the website in Polish language.
If I will create language file for the website, then I need to rework on whole project.
Is there any technique so that my website is automatically translated into Polish language when it is loading in browser. There also some hidden div's that will be displayed when a specific event occurs.
The website is created in php with smarty templating.
Please help me for this.
Thanks
If you want a custom solution, you're going to have to do some editing of your current code.
Option 1
Store all your strings in YAML files or within a database, or flat file, or however else you want them stored. The fact of the matter is that, as soon as your application loads, it'll query the database for the strings in your language (your url will have /en, /fr, /de etc at the end) and place those onto your page.
This means you'll have to code the retrieval of this data, and placement within your application.
Option 2
Use Google's "Auto Translate" as per Dainis' suggestion in the comments. This isn't as customisable, but means you don't have to do any reworking of your current code.
Option 3
Use Bing's translate API and manually request strings for the data you want translated on each request. Access to the Bing API is free for developers and has loads of free translations included - but this will be data intensive unless you cache the translations for future use.
With Option 3, you'll still have to code your own custom solution. So if you're on a tight deadline or you're just plain lazy, go with Option 2.

Multilingual website issues

I have to maintain a website in three languages: Arabic, English, and Pashto.
When the users select a language, for example arabic, when he applies any search in my website, how that search will be applied in my database?
When I'm updating the website (of course in english), how those updates will be reflected for arabic and pashto languages in the database?
First you have to decide what would be you database approach. Multilingual Site in Zend Framework
Secondly you have to decide what would be the approach to translated from one language to another. There are some options regrading this.
Add translated text for each language manually.
Use some translating service like google translate. But i dont think that you can rely on that. You have to add some approval system for translated text.
You can store multiple languages in an XML file (you can use http://php.net/manual/en/simplexmlelement.xpath.php to find what language you want based on the user`s selection), maybe even caching it...my opinion
Pro: further development (more languages)

PHP - how to translate a website into multiple languages?

I have a website that's currently in English; I want to be able to switch to a different language when a user clicks on a different language (there are little country flag icons on the site). The way I'm currently trying is with arrays, e.g.:
$english = array('index',
array('h1' => 'this is some h1 text',
'h2' => 'this is some h2 text'));
$japanese = array('index',
array('h1' => '世界交換への歓迎',
'h2' => 世界交換への'));
print $english[index][h1];
print $japanese[index][h2];
As you can see, if I did this for every single page in a separate language, it would be an insane amount of code. What other method can I try?
Given that you are looking for full i18n support which will eventually lead to l10n support, I would suggest writing your page in a PHP framework that supports these things out of the box.
Personally I've only done translations with the Symfony framework. They use a combination of i18n table extension in the DB for content, and XLIFF files for translations of the interface. It was fairly transparent once it was setup, and using a framework avoids having to write all this support by hand.
I also know that i18n is supported in Zend, CakePHP, and Code Igniter.
Content database (or file I guess)
Entry per page for each language
Language referenced by ID
ID set in $_SESSION variable
Optionally remembered in cookie for subsequent visits
I've used this system with a custom CMS # www.grandhall.eu. It gets especially fun when you need to take things like brochures & other downloads into account.
I'd suggest hooking your site into the Windows Live or Google Translate API's. I don't know about the Google one, but the Windows Live API seems really easy to use.
http://msdn.microsoft.com/en-us/magazine/dd569750.aspx
That, or you can write out all the content on the page in two languages, store them both in different tables in a "content" database, then change which table is loaded when the user clicks the change language button. Now, the majority of your drudgery would be in rewriting the content in both languages.
You could just use the Google translate api:
http://code.google.com/apis/ajaxlanguage/
It has tons of documentation and there are examples of how to use it on the google code playground:
http://code.google.com/apis/ajax/playground/
Just browse to ajax > translation

Categories