Nothing specific is present in thinBasic but if we can discuss a bit about that ... maybe we can produce something
Hi,
I can't find anything (bundled examples, manual, forum) about internationalization capability of thinbasic, maybe (or not) something similar to gettext.
- Did I miss something ?
- If no, what are your thought towards this (with thinbasic in mind) ?
Nothing specific is present in thinBasic but if we can discuss a bit about that ... maybe we can produce something
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
I assume we to be the community.
For my part: nothing unnecessarily complicated. I think that it's more convenient to code with internationalization in mind from the beginning than to review code afterwards. Do you agree ?
Then, do we want a solution specific to thinbasic or something compatible, or a mix of both : inspired from existing and as simple as possible in thinBasic ?
Something doable with AppConfig module can be something like that.
Create an XML file like the following and call it locale.xml
First level is locale codes, second level are keys and their traslations.
Keys are repeated in each language
<?xml version="1.0" encoding="utf-8"?><AppConfig> <en-GB> <Good_Morning>Good Morning</Good_Morning> <What_Is_Your_Name>What is your name?</What_Is_Your_Name> </en-GB> <fr-FR> <Good_Morning>Bonjour</Good_Morning> <What_Is_Your_Name>Quel est votre nom?</What_Is_Your_Name> </fr-FR> </AppConfig>
In script do something like that. Use .SetSearchKey method to set first level search to be the locale code, in this way in .GetKey method you just need to search for the key
Attached the files.uses "Console" uses "AppConfig" function TBMain() as long dim AppLocale as new cAppConfig dim sLocale as string '---Load translations AppLocale.Load(APP_SourcePath & "Locale.xml") if AppLocale.ErrorPresent Then '---Some error occurred printl "Error code", AppLocale.ErrorCode printl "Error description", AppLocale.ErrorDescription Else '---Set locale code sLocale = "en-GB" AppLocale.SetSearchKey(sLocale) printl "Setting locale to:", sLocale printl AppLocale.GetKey("Good_Morning") printl AppLocale.GetKey("What_Is_Your_Name") printl "" '---Set locale code sLocale = "fr-FR" AppLocale.SetSearchKey(sLocale) printl "Setting locale to:", sLocale printl AppLocale.GetKey("Good_Morning") printl AppLocale.GetKey("What_Is_Your_Name") printl "" end If printl "Press a key to end" in %CCOLOR_FLIGHTRED WaitKey end function
Just an idea.
Last edited by ErosOlmi; 29-10-2018 at 08:05.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
In the above example you can have multiple approaches:
- single file/all languages
- a file for each language
Files can be located anywhere.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Edited the files.
Why XML ?
AppConfig_Locale2.zip
Always interesting others source code.
I think there is an error: you used variadic parameter in i18n function. You need to call the function with variadic params inside () in this way:
https://www.thinbasic.com/public/pro...tions_subs.htm search for variadic.Printl i18n("s1_Is_My_Name",("DirectuX"))
Why XML?
Well because I like it, because it is very flexible and also because thinBasic has already AppConfig module done based on xml file format.
I also like jSon but to me they are more complicated to read when arrays of arrays ... are involved.
But we can find another way, other file formats and develop a specific thinBasic module for that if needed.
Just gives ideas
For the few documents I've seen, personally I do not like gettext complexity and its binary files and all the stuffs needed to convert files from one format to the other.
Instead I like the idea to find a way to read source code and determine which strings are to be covered by i18n conversion.
But this is only my opinion.
Thanks for this suggestion, I like it.
Hope to find a good way easy and flexible.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
True, missed that part.
It's up to you. I'm personally not in need of a module right now as some subs may do the work (As you may have understand, currently I just check If all the coding bricks are available for my project), however,
- code would be shorter with some dedicated properties/methods
- it would add a functionality to thinbasic
- it's an interesting thing to think at
we share this thought
For this : when right clicking on a tab, there is a contextual tool called "Indent Code", we may have "Generate translation file" and "Merge translation file"
Parsing the code for each i18n("...") call, and have the file built/updated.
Filename can also be retrieved from source code. Comments for translators too.
Two jointly Idea I'm not pleased with:'[i] <some comment to translators>
expand$ 's function usage in my code. (example1 below)
and
xml's format requirements for keys (example2 below)
see :
Because variable name doesn't need to be exposed to translator.(example1) would prefer s = expand2$("my name is %1, %2",(whaterverItsNameVariable1,whaterverItsNameVariable2)) rather than Dim stringVar as string Dim stringVar2 as string s = expand$ ("my name is stringVar, stringVar2")
I expected to find something to do this in the stringbuilder module but didn't.
More: % , $ ... are not accepted in xml tags(example2) would prefer s = expand2$("my name is %1, %2",(whaterverItsNameVariable1,whaterverItsNameVariable2)) with "my name is %1, %2" as a "key" or hash("my name is %1, %2") as key rather than s = expand2$("my_name_is_s1,_s2",(whaterverItsNameVariable1,whaterverItsNameVariable2)) with "my_name_is_s1,_s2" as a key , compelling to code AND edit the XML at the same time.
While I will think and study more about i18n (new to me and intrigued to find a clever solution), have a look at StrFormat$ to build strings from expressions and markers.
It uses {1}, {2}, ... {n} for placeholders
https://www.thinbasic.com/public/pro...strformat$.htm
Last edited by ErosOlmi; 29-10-2018 at 22:20.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Yes, this answers the example1 above.
Concerning xml , I am not against at all. It just implies invalid characters escaping, on the contrary of a plain text list (less error prone: one sentence per line, one separator between index and string, no escaping management when translating, enabling simple notepad to edit the file).
But let's keep it xml.
Xml file updated Locale2.zip
Bookmarks