Detecting the current user's language

Started by DaveMorton, October 11, 2011, 06:33:01 AM

Previous topic - Next topic

DaveMorton

I've read several threads with similar titles, but none of them answered my question, and I have yet to find a thread that tells me what I wish to know, so I decided to start my own thread on this issue.

I'm working on a mod that uses a different sort of CAPTCHA script (yes, I know... NOT ANOTHER one!), and this script utilizes support for non-English languages. What I'd like to know is if there's a variable within SMF that already "knows" the currently set language code (e.g. 'en' for English, 'de' for German, etc.)  so that I may pass it (or a variable based on it, if it's not already in ISO 639-2 format) to the CAPTCHA script. Take a look at this image:
(captcha_smf.php?lang=es)
for an example of the script in Spanish, to see what I'm referring to. My script supports English, French, Spanish, German, Dutch and Croatian at this point, and I plan on adding other languages in the future. Having access to a "language variable" of some sort or another would go a long way toward making this mod more successful. :)

Dzonny

Hello there and welcome to smf community.

So if i understood, you just need language codes for languages that you would like to add to your mod, and which smf uses?
If so, you can find it in string $txt['lang_dictionary'] in index.{language}.php file though.

Let us know if you have some sort of list of languages that you would like to add to your mod, so we can give you dictionary codes.

Regards.

DaveMorton

#2
Ideally, yes, that would be great, Dzonny. :)
I found index.english.php in the languages directory, so I'll read through that, and see what I can glean from it. I also found the variable $language within the SMF code this morning, and it seems to be useful (to a degree), as it seems to be currently set to 'english' in my install (I only understand English, personally). I can use the following code to translate that value into something more useful:


    $C4us_languages = array(
      'german'   => 'de',
      'english'  => 'en',
      'spanish'  => 'es',
      'french'   => 'fr',
      'dutch'    => 'nl',
      'croatian' => 'hr',
    );
    $C4us_lang_code = (!empty($C4us_languages[$language])) ? $C4us_languages[$language] : 'en';


And then use the variable $C4us_lang_code to apply the appropriate ISO 639-2 language code to my script. The only problem I see with that is if the variable $language uses different values for the language names ('e.g. 'espanol' for Spanish), in which case I would have to make the requisite changes to my code, above. :)

Dzonny

As i said, you can post a list of languages that you would like to add to your mod so i can help you about those codes. Also you can find them yourself, but you'll have to install languages which u would like to add yo your mod firstly and then see lang_dictionary string in index.language.php.

Regards.

DaveMorton

Thanks, Dzonny. For the time being, the only languages I'll be supporting (and therefor needing to install) are the ones I've already listed, above. I'll only be adding new languages in the future "by request", as some languages (Chinese & Japanese, for example) would be most difficult to add support for, for a lot of reasons. In the mean-time, I'll research adding those languages to my SMF dev install, and do some poking around, to see what I can learn. :)

DaveMorton

Ok, I went to Admin>Languages>Add Language and installed the languages I've listed above (this is on my local, development server, and not accessible on the Internet). The only language shown in the Edit Languages section is English, and it's also the only language in the listbox for default forum language. {sigh!} Nothing worthwhile is ever easy, is it? :)

Dzonny

DaveMorton, yes, the only language by default in smf installation pack is English. You can add more languages by chosing "add languages" from admin - languages section.

DaveMorton

Yup. I did that. For each of Spanish, English, French, German, Dutch and Croatian. I got the notification with each one that the language was installed correctly, yet only English shows up in the Edit Language page, and in the listbox under settings. I did, however, try to install just Spanish on the live server at hxxp:www.captcha4us.com/support/ [nonactive], and was successful there. So apparently there's a problem with my local installation of SMF that I'll have to look into.

Even with all of the challenges and obstacles, I was able to determine the information that I was looking for. The variable $txt['lang_dictionary'] holds exactly what I'm looking for, without needing to make any conversions at all. So now it's back to work on the mod. {happy dance} :D

Dzonny

I'm glad that you've find what you looking for.
Feel free to ask if you need any further help.

Regards.

DaveMorton

Thanks for your help, Dzonny. I do appreciate it. :) I marked the thread as resolved. :)

Advertisement: