Detect Iphone Language
Monkey Targets Forums/iOS/Detect Iphone Language
| ||
It would be nice to have some code to detect the actual phone language! Or there is a better approach to make multi-language games? |
| ||
If you wanted to do it "properly" then you would need to set up localizable.strings for each supported region in the XCode project then modify the source Monkey creates so that each string referenced the correct localized entry. >>Bunch of Apple info<< Monkey would ideally generate and hook-in this stuff but cross-platform localization is probably quite chewy so I wouldn't bet on seeing it any time soon. I concur that, in the interim, it would be nice to have a Monkey func that could get you the host locale so we could deal with the issue in our own way at least. It'd be a kludge but more practical than having to comb the Xcode proj by hand. |
| ||
then modify the source Monkey creates Haw... |
| ||
It needn't be a *complete* nightmare, I guess. You could box your string definitions then they'd at least be in one place...? |
| ||
Personally, I'd want to do it "properly", rather than some half-ass mix-and-match cross-platform thing that isn't native on all platforms. Each to their own, of course :-) |
| ||
Well that's what I'm saying. Box them in a Monkey class then they should be easy enough to locate and NSLocalizedString-alize in the XCode project. Is AngelFont up to handling Russian and Chinese (etc) character-sets or is all of this actually academic?! :D |
| ||
Has anyone tried this already? Multi language apps with Monkey? |
| ||
I do it this way (very loosely based on Brucey's Locale mod for Blitz!)Function GetLocaleText:String(tag:String) Local str:StringObject = TLocale.mapLanguages.Get(tag) If str Then Return str Else Return "@"+tag End Class TLocale Global mapLanguages:StringMap<StringObject> ' Need to load in tab delimited unicode file Function SetUp(lang:String = "en") mapLanguages = New StringMap<StringObject> ' Load continent data as a single string Local file:String[] = LoadString("Data/Languages.txt").Split("~n") Local index:Int = 0 For Local l:String = EachIn file[0].Split("~t") If l = lang Then Exit index+=1 Next If index >= file[0].Split("~t").Length Then index = 1 ' We now know which column we need to store in the map (index) file = file[1..] ' Skip header For Local line:String = EachIn file Local data:String[] = line.Split("~t") If data.Length > 1 Then mapLanguages.Set(data[0], data[index]) Next End End Then you just need all your strings stored in a UTF-8 tab delimited txt file (Monkey doesn't like csvs)... Tag en de es fr Tag_Language English Deutsch Español Français Tag_NationId 0 75 175 71 Tag_Translator Simon Read Guillermo Wallbrecher Chléo Achievement Achievement Achievement Logro Succès Add Add Adicionar Agregar Ajouter Add Friend Add Friend Freund hinzufügen Agregar Amigo Ajouter un Ami Advanced Advanced Fortgeschritten Avanzado Avancé etc Of course the user will have to choose their language at start-up but I guess if you could pull that info from the phone you could do it automatically. |
| ||
Double post. |
| ||
You can detect the language from the user settings on Ios like this: https://github.com/JochenHeizmann/Horizon-for-Monkey/blob/master/native/locale.ios.cpp |
| ||
That's great, thank you! |
| ||
sorry to awake this again. but at the moment I have to convert all my apps towards IOS and I need a couple of native functions. For language detection I found this link from maverick. but I get an error when I try to integrate a cpp function into a monkey app Strict Import mojo #if TARGET="ios" Import "Myios.cpp" Extern Class Locale="Locale" Function GetLanguageID$()="Locale::GetDefaultLanguage" End Public #end Class Game Extends App Method OnCreate%() SetUpdateRate 10 Return 0 End Method OnUpdate%() If TouchHit(0) EndApp() Return 0 End Method OnRender%() Scale 3,3 DrawText "V1",10,30 DrawText Millisecs(),10,10 DrawText Locale.GetLanguageID(),10,50 Return 0 End End Function Main%() New Game Return 0 End class Locale : public gxtkObject { public: static String GetDefaultLanguage() { NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0]; return String(language); } }; As it is my first combination of cpp and monkey I do not know, if it is a bug in the code, or I missed something or ....? |