简体   繁体   中英

Website localization

I would like to ask about best practices or the simplest way possible of translating static content. Eg translating, "search" or "save changes".

My current idea is:

depending on users browser locale (maybe geolocation of IP address, but I prefer browser locale) choose a subdomain, eg "fr.myweb.com". Set a cookie, session variable, depending on settings with the language. This part is fairly straightforward.

Now comes the translating part. Changing images depending on language wont be a problem, since a "_fr" prefix is enough. But translating strings like save changes, search, order items, etc. . Well, I am not sure here.

Since its all based on PHP and MySQL, I was thinking of something like:

Two tables:

  1. First one has list of all words in default language
  2. Second one has three columns (excluding auto increment) - language_id, translation, word_id

Get all words, cache the query or whatever and now calling trans('fr', 'search') would translate the word. This should work, although I dont know if its the right approach or if there is a better way. Note: No google translations.

Also since I use js/ajax, I am not sure about this part either. Get the language from cookie and do a map of alerts, etc. and then just call "message['fr']", I am not sure about this part either.

Any ideas what would be ideal for both languages? I tried google, but wasnt satisfied with the results. Any advice/link is appreciated.

Regards

Look up Gettext for PHP: http://php.net/manual/en/book.gettext.php . It's the de facto standard for providing web content translations. Basically you build translation files (you can use for example Poedit ), point PHP to them, set the locale to whatever is needed and use _( 'string to translate' ) to fetch the translations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM