Localization support for language identifier

Something’s wrong when a language identifier doesn’t have localization support. So I cooked up a little localization code for What Language Is This?, which proved to be not as easy as one might guess. That’s because some of the textual content of the web app is in HTML, other is generated by PHP, and yet other is generated in JavaScript. I wanted to have one single source of localized strings for all three output paths to simplify overviewing, translating, changing, and adding strings to the web app.

I’m not sure if there’s any good solution for this out there, but I cooked up my own. Each language translation has its strings in a text file formatted like an ini file with id keys and localized strings separated by an equals sign. You can view the English and Japanese raw text files if you like. These are read into a PHP array (i.e. dictionary), after first looking at what language is specified by the URL (/en for English, /ja for Japanese or any other code), and if that is not specified then looking at what languages the browser is set to prefer via the Accept-Language HTTP header. If the requested language is not available then default to English.

To get the html output localized, the php script that reads through and configures the app (the plain html file itself is set up to run offline for debugging purposes only) looks for string ids enclosed in percent signs, i.e. like %strings id%. These are then replaced with the localized strings from the dictionary. The php-generated content is trivially changed to look up strings from the dictionary. On the JavaScript side, I wanted access to the same string dictionary that I had on the php side, so this is inserted into a <script> block of the generated html output as a JavaScript object (i.e. dictionary). String id lookups can then be done on this object from the JavaScript code just like on the php side. In other words, the php string dictionary is converted into JSON, which is used from the JavaScript side.

あれ何語? What Language Is This? in 日本語

あれ何語? What Language Is This? in 日本語

It all works pretty well and meets my goals. The only downside is that it relies on the server to do some processing, so when I develop on the offline version the strings aren’t available, instead I get to see the raw string ids, which can be useful too, but you have to rely on imagination to envision the end result. Isn’t programming always like that anyway, though?

The first translated version of What Language Is This? is of course Japanese, done by myself and my wife (初めての共同作業? lol), not just because it’s easy for me to do, but also because when looking at the AddThis stats, Japan is the top ranking country, and also as you know the average English skills in Japan are pretty bad, so I suspect there is a demand for a Japanese translation. Looking at the access stats, and discounting those with good English skills (India, Netherlands, Scandinavia, for example), next in line would most likely be Spanish, French, and German, in that order. Anyone feel like helping? Please drop me a comment in that case. I can offer proper credit and a link back from the site in return.

Bookmark and Share

19 Responses to “Localization support for language identifier”

  1. Anonymous says:

    punten, ju naon nyet

  2. JORGE says:

    i have a picture from some languages but i dont know what it says.
    May you help me?

  3. Anonymous says:

    Language Identifier by Henrik Falck

  4. Daniel says:

    Hi, I´m a spanish member of wikipedia, and as I speak 5 occidental languages, I think I could help to help you with the most problematics examples… feel free to send me them. I know how to identificate not only the languages I speak but also the surrounders (like portuguese, italian, french, romanian, … polish, lithuanian, letonian… german, english, french..) Well just offering my help, if u find it not useful, don´t bother ;) Iki Pasymatymo!

  5. Gowrisankar N says:

    I am from India and i can help translate for “Tamil”, my mother tongue.

  6. Anonymous says:

    Got Deadbeats?
    Are you tired of people not paying you?
    Is your collection agency unable to collect for you?
    Put these deadbeats on DebtorsReport.com and you will be surprised how fast you collect the money.
    No Collection = No Fee
    We constantly contact the debtor by email and phone and don

  7. Donald Siano says:

    Hi, I think you have hit on very cool problem. It solved my question, what language is this at http://tank.offline.ee/masin/baka.html
    which references some of my work. Though I don’t see Estonian listed as one of the languages supported. Is this an omission?

    Thanks for the help!
    Don

  8. Mahdi says:

    Hello,
    I want use your service to detect language of urls .
    for example, the url is=http://www.yahoo.com
    so i want the result which shows “english”
    how can you help me on this ?????

  9. inez says:

    which language are these words taken from:
    bilda balda hulday
    adar adar adar
    mushta halda hulday

  10. Shraga says:

    Hello there! I was wondering if you knew anyone or maybe you could start up the site for translating audio. I have a piece of audio and I don’t know what language is briefly spoken and I would like to find out.. Is there anything avail like this?
    Thank you!

  11. Clarice says:

    Here’s an example of how blog touring or guest blogging works:.
    If you’re thrifty like I am, I’m sure you’ll easily be
    able to find something you love on Cafe Fashonista.

  12. Smithc899 says:

    Thank you for every other informative blog. The place else may just I get that type of info written in such a perfect means? I’ve a project that I’m just now working on, and I have been at the glance out for such information. ekgefbkbed

  13. I love reading through a post that can make men and women think.
    Also, thank you for allowing me to comment!

    Here is my web-site … comptoir quartz ou granit

  14. Kristopher says:

    This is a topic that’s near to my heart… Many thanks! Where aare your
    contact details though?

  15. Cheryle says:

    Do you mind if I quote a couple of your articles as log as I provide credit and soureces back to your site?
    My blog site is in the exact same area of interest as yours and my
    users would certainly benefit from some of the information you provide here.
    Please llet me know if this ok with you. Cheers!

Leave a Reply

Code*: