Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Attempt on Localization - Page 3 — Gideros Forum

Attempt on Localization

135

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited December 2013
    If you mean the title that is shown in IOS, then nothing to do with Gideros, it should be done the same way as described in your link (localizing InfoPlist.strings ) ;)
  • @OZApps
    @Chipster123, while that resource from IBM is a good reference point, are you sure that it works for you on the iOS devices? For ZDay I had to get Chinese and English working, with Chinese, I can see zh_Hans_XX and zh_Hant_XX but I had to just use the zh_Hans or the zh_Hant (which is Hans for simplified and Hant for traditional, we went with simplified only)
    What font did you use for this? And could you get a mix of English and Chinese in the same instance for English words that have no Chinese translation?
  • I have been working with this  localization too: poeditor.com and it really does a great job. It support a large number of translators on the same project, working on different languages. There are also plenty of features that ease the work.It has API and github integration also.
  • was looking for a localization library and wow another gem from Arturs! I cannot thank you enough for all the code you created and shared with community.

    Likes: ar2rsawseen

    +1 -1 (+1 / -0 )Share on Facebook
  • boriskeyboriskey Member
    edited October 2014
    Hi @ar2rsawseen

    you have this example
     local text = TextField.new(font, string.format("Hello, %s", "Arturs")
    What if my string parameter needs to be localized as well and that parameter is actually a variable. Something like that:
     local text = TextField.new(font, string.format("Animal Name: %s", curAnimalName)
    And then curAnimalName can contain 90-100 names which need to be localized.

    And here is another example - I have a table below and need to localize table values.
    self.questions = {'ONE','TWO','THREE','FOUR','FIVE','SIX','SEVEN','EIGHT','NINE','TEN'}
    I am thinking about making data variable global in your Localize.lua and then I access localized values like this:
     local text = TextField.new(font, string.format("Animal Name: %s", Localize.data[curAnimalName])
     
    self.questions = {Localize.data["ONE"],Localize.data["TWO"]}
    Is there a better way?
  • ar2rsawseenar2rsawseen Maintainer
    edited October 2014
    @boriskey what Localize does is creating a wrapper function around existing method, and simply checks if provided value is in the localization table.

    So it does not matter if you provide a variable or string value, it should localize it.

    There is no localization for tables, but not the way you hold the string matters, but how you use it later.

    so if later you will still do something like:
    for i = 1, #self.questions do
        TextField.new(nil, self.questions[i]) -- the string will be localized here
    end
    It will either way be localized when you use it

    the library was designed to localization would happen completely seamlessly without the changes in the code ;)

    If something is not working as expected, well that is another problem, try to provide small example that demonstrates the issue, and I'll look into it ;)
  • i guess I am doing something wrong here.

    here is an example using your sample project.

    I added these lines to ru_RU.lua
    l["wolf"] = "Волк"
    l["bear"] = "Медведь"
    l["Animal is %s"] = "Животное %s"
    and this in the main.lua:
    local curAnimalName = "bear"
    local text2 = TextField.new(font, "Animal is %s"..curAnimalName)
    text2:setPosition(0,300)
    stage:addChild(text2)
    It does not work...

    But yes, If you do this, it works:
    local curAnimalName = "bear"
    local text2 = TextField.new(font, curAnimalName)
    text2:setPosition(0,300)
    stage:addChild(text2)
    Does it make sense?
  • @boriskey you should do it like:
    local curAnimalName = "bear"
    local text2 = TextField.new(font, string.format("Animal is %s", curAnimalName))
    text2:setPosition(0,300)
    stage:addChild(text2)
    because other way you simply have a concatenated string: "Animal is %sbear"
    which does not match any localized string
  • Ah I see, where the problem is
    string.format is set to only localize first parameter, for some reason :)

    You need to open Localize.lua and change:
    load(string, "format", 1)
    to
    load(string, "format", {1,2})
    so it would try to localize both parameters ;)

    Likes: boriskey

    +1 -1 (+1 / -0 )Share on Facebook
  • works perfect now! I knew you had a better way to tackle this :) Thanks a lot!
  • unless I am missing something again, looks like it does not work when string.format parameter is a number:
    local score = 1000
    local text2 = TextField.new(font, string.format("Score: %d", score))
    text2:setPosition(0,300)
    stage:addChild(text2)
    I tried both %d and %s
  • @boriskey what do you mean by not working? Number is not localized? :D

    But seriously is there an error? Or what would be expected output that you can't achieve? :)
  • lol I am sorry, I should've been clearer. In the example above the number won't be showed at all, so "Score: %d" will be localized but %d will be replaced with nothing. So you will see "Очки: " and no number after it.
  • Hmm, that's interesting, because I just tried and in my case both:
    print(string.format("Hello, %s", 1))
    and
    print(string.format("Hello, %d", 1))
    outputted number and localized text

    the only way it does not provide number is when I use:
    print(string.format("Hello, ", 1))
    are you sure you have %s or %d in your localized string to which original string is changed? Because it is changed before being processed by string.format

    Likes: boriskey

    +1 -1 (+1 / -0 )Share on Facebook
  • boriskeyboriskey Member
    edited October 2014

    are you sure you have %s or %d in your localized string to which original string is changed? Because it is changed before being processed by string.format
    shame on me - forgot to put %d in a localized string

    thank you for your help!

    Likes: ar2rsawseen

    +1 -1 (+1 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited February 2018
    Guys! I'm testing @ar2rsawseen 's Localize.lua
    Why it doesn't work after exporting APK?
    (app starts, but shows default english text, not localized, though my locale is ru_RU)
    The project works normally while testing on PC and Gideros Android Player.
    Some permissions have to be set? I've tried to add plugins 'Require' and 'Lua file system' to the project, it didn't help.

    p. s. here's .gproj & exported apk of my test app:
    https://www.dropbox.com/s/wrx2mbqw3lclnoe/localizationTestProject.zip?dl=0

    I've tried with/without 'string.format', with/without array.
    txt1 = TextField.new(segoe, myArr[1])
    txt4 = TextField.new(segoe, string.format("How are you", 1))
    txt3 = TextField.new(segoe, "Detected lang: "..application:getLocale()) --shows ru_RU
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • виведи десь на екран текст
    application:getLocale()

    і скомпіль, і потесть шо видає
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • This is what I wrote for my programs, works fine for me:
    function arabicProcessing(text)
    	local Achar={0x002,0x024,0x062,0x084,0x0C4,0x104,0x144,0x184,0x1C2,0x1E2,0x202,0x222,
                                   0x244,0x284,0x2C4,0x304,0x344,0x384,0x3C4,0x404,0x440,0x440,0x440,0x440,0x440,0x440,
                                   0x444,0x484,0x4C4,0x504,0x544,0x584,0x5C4,0x602,0x622,0x644}
    	local last=0	
    	local rtext=""
    	for p, cur in utf8.codes(text) do 
    		if ((last>=0x627) and (last<=0x64A)) then
    			local A=Achar[last-0x626]
    			local unibase=0xFE8D+(A>>4)
    			local of=0 --0=iso,1=fin,2=ini,3=med
    			if ((cur>=0x627) and (cur<=0x64A)) then
    				of=2+state
    			else
    				of=state
    			end
    			state=1
    			if (of>=(A&0xF)) then of=0 end
    			of=of+unibase
    			rtext=rtext..utf8.char(of)
    		else
    			if last>0 then
    				rtext=rtext..utf8.char(last)
    			end
    		state=0
    		end
    		last=cur
    	end
    	if last>0 then
    		rtext=rtext..utf8.char(last)
    	end
    	text=""
    	for p, cur in utf8.codes(rtext) do
    		if cur==0x28 or cur==0x29 then cur=cur~1 end
    		text=utf8.char(cur)..text
    	end
    	return text
    end
     
    local translated={}
     
    pcall(function() require "lsqlite3" end)
    src_db="zombierocks.db"
    dst_db="|T|zombierocks.db"
    if file_exists(dst_db) then
    	file_delete(dst_db)
    end
    file_copy(src_db,dst_db)
     
    if sqlite3 then
    	local db=sqlite3.open(dst_db,sqlite3.OPEN_READONLY)
    	if db then
    		local sql=db:execute("PRAGMA temp_store=2;")
     
    		osLanguage=lower(sub(application:getLanguage(),1,2))
    		message("Language_"..osLanguage)
    		if osLanguage=="pt" then osLanguage="pb" end -- brazil and portugal share the same language
     
    		--osLanguage="ar" -- language to test
     
    		if osLanguage~="en" then
    			local found=false
    			local sql=db:prepare("PRAGMA table_info(languages);")
    			if sql then
    				for n,l in sql:urows() do
    					if l==osLanguage then
    						found=true
    						break
    					end
    				end
    			end
     
    			if found then
    				local sql=db:prepare("SELECT en,"..osLanguage.." FROM languages;")
    				if sql then
    					for w,t in sql:urows() do
    						if t and t~="" then
    							if osLanguage=="ar" then
    								osRightToLeft=true
    								t=arabicProcessing(t)
    							else
    								local conv={"ę","e",
    											"Ő","Õ",
    											"ő","õ",
    											"Ű","Û",
    											"ű","û",
    											"ý","y",
    											"’","'",
    											"“","'",
    											"”","'",
    											"…","..."}
    								for loop=1,#conv,2 do 	-- replace letters our font doesn't have
    									t=gsub(t,conv[loop],conv[loop+1])
    								end
    							end
    							translated[w]=t
    						end
    					end
    				end
    				local n={"fr","it","se","hu","es","pb","ru","cs","ja"}
    				for loop=1,#n do
    					if n[loop]==osLanguage then
    						narrow=0.8 -- set x scale  multiplier for certain languages
    						break
    					end
    				end
    				if osLanguage=="ru" then narrow=0.7 end -- custom width for specific languages
    			end
    		end
     
    		db:close()
    	else
    		message("No_database")
    	end
    else
    	message("No_sqlite3")
    end
     
    local function translate(t)
    	return translated[t] or t
    end
    I have a sqlite database with a key field called "en" and other fields that are the two letter language code, eg "fr".

    If the English text column has the string and the specific language column has some text then it will use that text, else the original text will be used. Because it uses the string as the table id then it's fast enough.

    To use I just put something like:
    translate("Rocks, People & Plants!")
    I have this earlier on to make some string functions faster:
    local sub,len,upper,lower,format,gsub=string.sub,string.len,string.upper,string.lower,string.format,string.gsub

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Apollo14Apollo14 Member
    edited February 2018
    oleg said:

    виведи десь на екран текст
    application:getLocale()

    і скомпіль, і потесть шо видає

    application:getLocale() --it shows ru_RU, but ru_RU.lua doesn't work
    @oleg do you use Localize.lua class in your projects, you had no problem with that?

    @SinisterSoft thx a lot! I hoped that @ar2rsawseen 's Localize.lua will work. :(
    Did somebody successfully use his Localize.lua class?
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • For games I think the faster the better and so a straight translation table seems best over using a class.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • @Apollo14 я не перевіряв просто ідеї:
    на файлі ru_RU.lua виключив "exсlude from execution"?
    спробуй ru_RU.lua кинути в корінь і напряму написати io.read("|R|ru_RU.lua")
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • Apollo14Apollo14 Member
    edited February 2018
    after further testing it seems that 'Localize.lua' is pretty much broken, maybe @ar2rsawseen will take a look at it someday :)

    @SinisterSoft 's variant looks good but I'm not familiar with most of the code there, I'll have to learn how to work with sqlite later on

    I think for starters I'll try to stick to the simplest method:
    mainArr= {"Hi dude!","How are you?","How is mom?"}
    esES = {"Hola amigo!","Cómo estás?","Cómo está mamá?"}
     
    if application:getLocale() == 'es_ES' then
    	mainArr = esES
    elseif application:getLocale() == 'tr_TR' then
    	mainArr = trTR
    --etc...
    end
     
    txt1 = TextField.new(segoe, myArr[1])
    --etc...
    P. S. @SinisterSoft could you please show some very basic variant of doing it with sqlite?
    Like if we had only 3 phrases to localize (in my code above).
    THANKS!
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • SinisterSoftSinisterSoft Maintainer
    edited February 2018
    I use sqlite db browser ( http://sqlitebrowser.org/ ) to create and edit a database, I then include the database with my project and add the luasqlite plugin to the project.

    I've attached two pictures showing the database structure and an example of what a populated database looks like.

    You then load the code and just use something like:
    txt1=TextField.new(segoe,translate("Hi dude!"))

    2018-02-28_15-38-48.png
    1576 x 500 - 40K
    2018-02-28_15-38-01.png
    1192 x 490 - 54K

    Likes: Apollo14

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
  • totebototebo Member
    edited March 2018
    I've translated one of my game, Fast Food Rampage, into a number of languages. I used Google Docs instead of a database, which helps a lot because you can share the document directly with the translators.

    Each row in the spreadsheet has an "id" column, then a column for each language (with the language code as its title).

    Then it's exported to CSV which is loaded by Gideros when the app starts. I detect which locale the device uses. Then, to get a translated text I just go:
    local str = translate( id )
    It worked really well. Thanks to Nicoll Hunt leading me down the right path on that one.

    My Gideros games: www.totebo.com
    +1 -1 (+3 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    edited March 2018
    yes, csv file could be used instead of a database table, json table, etc...
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • @totebo hello there, I tried to translate to arabic with no luck. I can use arabic in java (on android) with no problem but with gideros I am at lost. I used the same approach as you (an excel file with headers) that works great.

    My problem is I searched but could not find how to load a csv and read from it in gideros. Could somebody give me some advice please?

    It is my last resort to try to translate to arabic using this method :blush:

    Thank you.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • MoKaLux said:

    @totebo hello there, I tried to translate to arabic with no luck. I can use arabic in java (on android) with no problem but with gideros I am at lost. I used the same approach as you (an excel file with headers) that works great.

    My problem is I searched but could not find how to load a csv and read from it in gideros. Could somebody give me some advice please?

    It is my last resort to try to translate to arabic using this method :blush:

    Thank you.

    here's some info on parsing CSV:
    http://giderosmobile.com/forum/discussion/6520/csv-parser/p1
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • thank you Apollo14 for the prompt reply. I saw that post doing my research but did not try all the csv code. Now I have clicked on all of them and github.com/geoffleyland/lua-csv may do the trick. Thanks again. I am trying it right away! I will let you know.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • I give up! going back to java :-(

    libgdx here I come!
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Sign In or Register to comment.