Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: i18n internationalization functionality in thinbasic / thinair

  1. #1

    i18n internationalization functionality in thinbasic / thinair

    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) ?

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10
    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

  3. #3
    Quote Originally Posted by ErosOlmi View Post
    we can discuss a bit about that ... maybe we can produce something
    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 ?

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10
    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
    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
    
    Attached the files.
    Just an idea.
    Attached Files Attached Files
    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

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10
    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

  6. #6
    Quote Originally Posted by ErosOlmi View Post
    Attached the files.
    Just an idea.
    Edited the files.

    Why XML ?

    AppConfig_Locale2.zip

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10
    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:
    Printl i18n("s1_Is_My_Name",("DirectuX"))
    
    https://www.thinbasic.com/public/pro...tions_subs.htm search for variadic.


    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

  8. #8
    Quote Originally Posted by ErosOlmi View Post
    You need to call the function with variadic params inside ()
    True, missed that part.

    Quote Originally Posted by ErosOlmi View Post
    develop a specific thinBasic module for that if needed.
    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


    Quote Originally Posted by ErosOlmi View Post
    I do not like gettext complexity and its binary files and all the stuffs needed to convert files from one format to the other.
    we share this thought

    Quote Originally Posted by ErosOlmi View Post
    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.
    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.
    '[i] <some comment to translators>
    
    Two jointly Idea I'm not pleased with:
    expand$ 's function usage in my code. (example1 below)
    and
    xml's format requirements for keys (example2 below)
    see :
    (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")
    
    Because variable name doesn't need to be exposed to translator.
    I expected to find something to do this in the stringbuilder module but didn't.

    (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.
    
    More: % , $ ... are not accepted in xml tags

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10
    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

  10. #10
    Quote Originally Posted by ErosOlmi View Post
    have a look at StrFormat$ to build strings from expressions and markers.
    It uses {1}, {2}, ... {n} for placeholders
    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

Page 1 of 3 123 LastLast

Similar Threads

  1. MLGrid: new sheets functionality
    By ErosOlmi in forum UI (User Interface)
    Replies: 0
    Last Post: 06-09-2011, 11:30
  2. How would you implement an Undo functionality in an app?
    By Michael Hartlef in forum General
    Replies: 8
    Last Post: 20-08-2010, 19:03
  3. Print functionality
    By ErosOlmi in forum thinAir General
    Replies: 0
    Last Post: 17-10-2005, 16:55

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •