Jefrey

i18n library

1 post in this topic

#1 ·  Posted (edited)

I needed to create a simple i18n library for an open-source project I've worked on last week.

So I made this simple and easy to use.

When translating, you have two options: the first one is to use a global file on the following format:

[language_code]
text_id=Translation
text_with_format=Number: %.2f
text_with_parameter=Hi %s

[another_language_code]
text_id=Tradução
...

The second option is to separate every translation into files named language_code.lng in a folder of your choice. Note that every file on this folder will have the following format:

[language_code]
text_id=Translation
text_with_format=Number: %.2f
text_with_parameter=Hi %s

The language code can be ISO 639-1 (2 chars, like "en", "pt", "es") or culture code (including the country, like "en-US", "pt-BR", "es-ES"). You can use both these formats on the same file/project without any problem.

Finally, use the _() function to get your translation text. It accepts the following syntax:

_($sText_id [, $sPar1 [, $sParn ] ] )

The parameters are optional, but the maximum number of parameters is 32. If you need more than 32 parameters (sure?), please consider splitting your string into multiple ones.

Note that everything is explained on the Example.au3 (see online) and Example.lng (see online) file.

Interesting note (source):

I18n - Internationalization - Providing some kind of framework so that you can easily swap out strings, graphics, sounds and other resources and generally handling different conventions of communication.

L10n - Localization - The process of creating a bunch of strings, graphics, sounds etc. so that you can target a specific nationality, language or region.

G11n - Globalization - Doing both Internationalization and Localization steps

 

Download: AutoIt Files

Fork me on Github

Edited by Jefrey
1 person likes this

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path Random stuff Super Mario beep sound your ears will hurt

 

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • jonson1986
      By jonson1986
      Hello I'm trying to translate few text using below code, I found it working previously couple of months ago but Now these days it's not working at all and I'm getting below errors when I run the script and Array display at the end of text also not able to show any translated text instead of value 0 & 1;
      --> IE.au3 T3.0-2 Warning from function _IEGetObjById, $_IESTATUS_NoMatch (gt-res-data)
      --> IE.au3 T3.0-2 Error from function _IEPropertyGet, $_IESTATUS_InvalidDataType
      Here is code,
      #include <IE.au3> #include <Array.au3> Local $tag="* # * # *" Local $oIE=_IECreate("https://translate.google.com/#auto/es") Local $oForm=_IEFormGetCollection($oIE,0) Local $oQuery=_IEGetObjByName($oForm,"text") _IEFormElementSetValue($oQuery, $tag & @CR & "Hello World" & @CR & "This is a test" & @CR & $tag) _IEFormSubmit($oForm) _IELoadWait($oIE) Local $oText=_IEGetObjById($oIE,"gt-res-data") $lines=StringSplit(_IEPropertyGet($oText,"innerText"),@CRLF,1) _IEQuit($oIE) _ArrayDelete($lines,_ArraySearch($lines,$tag,1,0,0,1,0) & "-" & $lines[0]) _ArrayDelete($lines,"1-" & _ArraySearch($lines,$tag,1,0,0,1,1)) $lines[0]=UBound($lines)-1 _ArrayDisplay($lines)  
    • pinkfoyd
      By pinkfoyd
      Hi,
      Here is a tool coded in AutoIt to edit multiple ini files ( up to 8 at the same time) to include multilanguage support in your script.

       
       
      The script himself have multilanguage support, simply by using :
      To change language, i read my global.ini file witch inform me what ini file i had to use...
      ConsoleWrite ( _string_lang(19) ) Func _string_lang($number) $number = _StringRepeat("0",6-StringLen($number)) & $number $string = IniRead($my_ini_folder & $interface_ini_file,"STRING",$number,"NOT_FOUND") Return($string) EndFunc  
      where 19 is the 19 string in ini file witch look like this :
       
      Todo : Initial ini file not necessarily "english.ini"
       
       
      Feel free to use it, give me idea, critical or bug found.....
       
      As i am french please be gently
       
      Multilangue_autoit.zip
    • martinstut
      By martinstut
      While developing an AutoIt-based application for an international christian organization, the need came up to provide this application for users of different native languages. So MsgBox(64, "App Title", "Please reboot your computer to complete the process.") is no longer good enough. The application needs to present its user interface in a different language, depending on the user’s preference.
      Of course there are many approaches to implement this. But however you do it, you will need two different toolkits: one for the translator and one for the programmer.
      The programmer will need something to define the translatable strings or, preferably, extract them from the source code.
      The translator will need something to edit the translation.
      The programmer will need something to incorporate the translation in to the program.
      And all of this should be repeatable with little effort when a few strings in the program change – don’t make the translator retranslate everything if you just add two strings for a new little feature of your program.
      To avoid reinventing the wheel, I decided to go the route many large open source projects go: gettext.
      So I've built a small toolkit utilizing the style and some tools of GNU gettext to create AutoIt applications that can be translated into any language by just adding a corresponding [language].po file.
      I've explained the reasoning and overview in https://martinstutenglish.wordpress.com/2016/06/10/internationalizing-autoit-applications-by-something-similar-to-gnu-gettext/
      Technical details and downloadable files, including a very small example application, are in https://github.com/martinstut/gettext_au3 (updated as I improve the toolkit), most of which is also contained in the attached ZIP file.
      Hopefully this helps you to internationalize your own applications.
      gettext_au3-20160617.zip
    • TheSpannish
      By TheSpannish
      Estoy traduciendo este projecto 
      al español que esta mal traducido, son 1000 lineas de frases, para mi es mucho, si alguien que sepa español puediera ayudarme se lo agradeceria
    • gononono64
      By gononono64
      Hey,
      So I'm trying to create a translation script to translate text from english to spanish. It seems my program crashes if i have more than 1 child in the html.(i will highlight it via comment) I am also occasionally crashing after my 5 second, while busy, loop. Any help or insight would be greatly appreciated.
       
      $langFrom = "en" $langTo = "es" While 1 Sleep(250) Translate() Wend Func Translate() $ie = ObjCreate("InternetExplorer.Application") $ie.visible = True $toTrans = InputBox("Translate", "Enter text to translate [" & $langTo & "]") $ie.Navigate("https://translate.google.ca/?ie=UTF-8&hl=" & $langFrom & "&client=tw-ob#auto/" & $langTo & "/" & $toTrans) $result = "" While($ie.busy) Sleep(5000) WEnd ;occasionally crashing here (unsure cause) While($result = "") $result = $ie.document.getElementById("result_box").innerHTML sleep(250) WEnd $children = $ie.document.getElementById("result_box").childNodes ;suspect i did something wrong here $result = "" for $child in $children $result = $result & $child.innerHTML & " " ;crashing here Next ;cleanup $result = StringReplace($result," "," ") $result = StringReplace($result," ."," ") $ie.quit() MsgBox(0,"Translated", $result) EndFunc