larsiusprime / firetongue

A translation/localization framework written in Haxe
MIT License
144 stars 32 forks source link

Auto-detect system language #1

Closed AndreiRegiani closed 10 years ago

AndreiRegiani commented 11 years ago

Hey Lars,

[flash.system.Capabilities.language] returns current system language ("en", "es", "fr", "ge"), I think that should be default when no value is passed on init(), and have a function to use system language.

Also, 99% of games don't have to deal with measures/time/signs/etc, only the language, so the default folder structure should be only the language code ("en" instead of "en-US", "en-CA", "en-GB"), this way the auto-detect above would work as default.

Great library! Thanks

larsiusprime commented 11 years ago

Hey, thanks for this!

1) I can definitely make it try to guess a default language from the Capabilities object if none is provided. The logic should probably be:

2) About 2-character vs. 4-character language ID strings, this is a bit complicated. First of all, the whole issue of language classification is kind of unsolved. The reason I use the 4-character classification (language + "region") is to give the system the best chance of having as much flexibility as possible to deal with the many differences in regional dialects (for instance, in my own home country, Norway, there are two official "Norwegian" languages that are quite different, if you only speak one of them it's very difficult and almost impossible to understand the other). Also, in case of any overlaps in 2-letter abbreviations, having the extra region code helps sort out any ambiguity.

That said, I agree that 99% of games won't need that level of fine-grained control, but I'd still like to leave the option there. So, the system should be able to accept 4-character and/or 2-character classifications if the user so desires.

In any case, whatever sort of locales the player provides, the game should be able to use Capabilities to detect the default 2-letter string and make a match based on the above logic in 1)

larsiusprime commented 11 years ago

What I might do is just follow the IETF language tag standard, which accepts a variety of language tags, both short and long.

AndreiRegiani commented 11 years ago

That's perfect :) Btw, I'm using FireTongue in my project, just to confirm you that I had no issues testing on iOS, Mac and Flash.

On Aug 4, 2013, at 5:16 PM, Lars Doucet notifications@github.com wrote:

What I might do is just follow the IETF language tag standard, which accepts a variety of language tags, both short and long.

— Reply to this email directly or view it on GitHub.

larsiusprime commented 11 years ago

I'll get around to this feature soon, just doing some other things at the moment. Please report any other issues you find!

as3boyan commented 11 years ago

I thinks language selection screen at start is better(for desktop app), but for flash game, auto detection is very cool!

larsiusprime commented 10 years ago

Auto-detection is now in (on the dev branch). The programmer can always provide their own language selection logic in their own app.

On my machine, most targets return "en" as the default locale, and then if it doesn't find that it looks for the closest match -- in my tests it recognized this "en-US" as the best match, exactly what I want it to do. Should work for other situations in the exact same way.