Hello,
wanted to try something on localization in Gideros and here is the result of my attempt.
http://appcodingeasy.com/Gideros-Mobile/Localization-in-GiderosBasically it loads language constants for user's locale or default locale, and provides methods to simply access constant values, format them printf style, or get ready to use Text objects or images
Any comments, suggestions, criticism is appreaciated. And if anyone find it useful, feel free to use in your projects.
Comments
It's interesting that you should post this now as I was just thinking about something similar. These are my thoughts so far just in case you'd like to incorporate any such ideas into your own Locale code.
The two differences I was considering compared with your implementation are:
1) Instead of requiring the code to be written with localisation in mind I was planning to allow existing code to "just work". The way I'd do this is by redirecting existing API functions that take strings to my localised versions. This would be done in Locale:init().
2) In addition, in order to use unmodified code, I was planning to index into the locale tables using the original strings themselves. I think this should be quite fast enough since I imagine that Lua uses hash tables internally to perform the table lookups (@atilim?). Also, it's usually going to be a one off time penalty that happens on scene load rather than every frame update.
Here's a demo I knocked up this morning after seeing your post. First time you tap it will run the showFields() function with no locale. Notice this is just normal Gideros code not written with any localisation in mind. Next time you tap it forces a french locale and runs the function again. the third time it uses the current locale (which won't exist unless you are in UK, US or FR). If a definition for the current locale does not exist then it defaults to en_US.
Let me know what you think.
Likes: chipster123, avo
I wasn't sure it is possible to override other classes' constructors in such a way, but it works, Thank you for this tip, I'll experiment a little more with it.
Now object Localize is global and non-instantiable, meaning, you don't need to create an instance. That is why it is now completely seamlessly integrated, simply include it in the project.
Plus it provides a method, which allows easy overriding of some optional objects, like Sound, URL and any other, to also support seamless localization.
Updated docs and sample project here:
http://appcodingeasy.com/Gideros-Mobile/Localization-in-Gideros
Likes: bowerandy
I think the only thing I would have done differently is to not use a traditional Lua "module" but to stick within the object-oriented paradigm and make the load function a static function of a class:
Best regards
PS: I think the video on your site is still the original and not updated for your new method.
Best regards
But yeah, it's not possible to set custom location, mostly because of code execution order.
I guess instantiable approach might have been better.
I'd only like to know one thing:
how it's handled internally? and which is better for performance?
Does anybody know?
I agree that the seamless approach is enticing but you could still do that by treating Localize as a singleton class and automatically instantiating the default instance using the current local. Then if the programmer wanted to override the default localizer they only need to replace this default instance with another one. E.g. in Localize.lua:
Localize.lua:30: assertion failed!
stack traceback:
What should i do?
The error is because the localization file does not exist. My fault, I should have done the fallback to default localization file. I'll fix it ASAP. Thank you
It should accept all available locale files, not only russian
1.lv_LV
2.ru_RU
I just checked and it works.
Well you can experiment by creating new locale files (same format as existing) and adding them to Gideros project inside Gideros Studion in locales folder.
I guess that might be the reason why some languages display English rather than the unicode language selected in the text string. Most non unicode languages would work just fine if the characters are part of the ASCII set.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
https://github.com/ar2rsawseen/Localize
Likes: unlying
I've added: localize.lua, textwrap.lua (although I don't use it) , three different localized files located in the locale/ folder .
For example here is my localized Spanish file named: es_ES.lua
I call it in one of my lua pages
Should I be adding this below to the localized file? Defining the "up" in
I know it should work and I've followed the example. Should it derive from the main.lua instead of a scenecontroller page?
which is the latest version?
- Github : https://github.com/ar2rsawseen/Localize/blob/master/Localize.lua linked on the Gideros tools page
- or this one : http://appcodingeasy.com/my_classes/gideros/Localize/Localize.zip as linked at AppCodingEasy
My guess is that the first one is the right one, but if a user goes to see the documentation at AppCodingEasy then downloads, he is not directed to the GitHub version.(by the way how do you make tests to see if the class works, I don't know how to application:setLocale() so the english version is always displayed in the code sample?)
Did you mean to test the application:getLocale() ?
You just need to change device's language at Setting.
Also, for iOS, you might need to generate that *language*.lproj and add the language accordingly, so itunesconnect can detect which language is supported for your app.
I'll try
After uploading, when you see App for each version, there is Binary Details at the right, below the Promo Codes. That is what i mean.
I thought there was a way to force a locale directly inside Gideros, but it seems that it's not possible?
To test different locales, you could do something like: