| View previous topic :: View next topic |
| Author |
Message |
ristoi General User


Joined: 25 Aug 2009 Posts: 24 Location: Järvenpää
|
Posted: Wed Jul 07, 2010 9:18 am Post subject: Function for language determination |
|
|
I write small helper function for UIs of multilingual dialogs and windows. Function iKieli get language code from active document (thisComponent) and return corresponding number, if this language is found in sKielikoodit list (actualy string). If there is not the same language code in the list, function returns a default number (1). Now this correspond to suomi but it can be changed.
Moreover function use optional sKlyhenne argument to return language code string (like "en") even if this language is not yet implemented (or localized) for this function. Of course the language must be localized in OpenOffice.
This function alone is not very indepentend but it works quite well with my other routines which I am going to introduce in separate posts. What more I can say? The upper limit of number of possible different language codes is now about 600 but only fi, et, pl, es, fr, de, da and cs is implemented. Next is easy to add if needed.
Regards
Risto
| Code: |
Function iKieli (optional sKlyhenne as String) as Integer
REM iKieli-funktio palauttaa järjestysnumeron muokattavasta kielikoodien jonosta.
REM valinnainen argumentti sKlyhenne-voi palauttaa kielikoodin
DIM sKielikoodit as String, sKKoodi as String
DIM iKnro as Integer
On Local Error GOTO Virhe:
REM haetaan kielikoodi tekstimuodossa asiakirjan oletuskielestä
sKKoodi = thisComponent.CharLocale.Language
REM palautetaan valinnaisesti myös kielitunnus tekstinä
IF NOT IsMissing(sKlyhenne) then sKlyhenne = sKKoodi
REM uuden kielen voi lisätä jonon jatkoksi, vaikka xx:n paikalle:
REM iKnro-> --1--2--3--4--5--6--7--8--9--10...
sKielikoodit = "fi et pl es fr de da cs xx ??"
iKnro = 1 + InStr(sKielikoodit,sKKoodi)/3 'Väleineen 3 merkkiä / kielikoodi!
REM Oletuskieli on nro 1. Nyt "fi", mutta on vaihdettavissa.
IF iKnro = 0 then
iKieli = 1
else
iKieli = iKnro
EndIf
Virhe:
Resume Next
End Function 'iKieli
|
|
|
| Back to top |
|
 |
ristoi General User


Joined: 25 Aug 2009 Posts: 24 Location: Järvenpää
|
Posted: Thu Jul 08, 2010 4:53 am Post subject: |
|
|
Thinking twice and changing routine so that it can take list of used languages as parameter: I add optional argument sValikoima. Now this helper routine is not limiting used languages but only selecting one and returning values of selection. In sValikoima string new default language is the first one in the string, not necessary "fi".
Changes are such that calls for former version is working too with this version. So I keep the name same.
| Code: |
Function iKieli (optional sKlyhenne as String, Optional sValikoima as String) as Integer
REM palauttaa järjestysnumeron muokattavasta kielikoodien jonosta.
REM valinnainen argumentti sKlyhenne voi palauttaa kielikoodin
REM valinnainen argumentti sValikoima sisältää käytettävän kielivalikoiman
'
DIM sKielikoodit as String, sKKoodi as String
DIM iKnro as Integer
On Local Error GOTO Virhe:
REM haetaan kielikoodi tekstimuodossa asiakirjan oletuskielestä
sKKoodi = thisComponent.CharLocale.Language
REM palautetaan valinnaisesti myös kielitunnus tekstinä
IF NOT IsMissing(sKlyhenne) then sKlyhenne = sKKoodi
REM oletuskielikoodit ilman ulkopuolista "tilausta":
REM uuden kielen voi lisätä jonon jatkoksi, vaikka xx:n paikalle:
REM iKnro-> --1--2--3--4--5--6--7--8--9--10...
sKielikoodit = "fi et pl es fr de da cs xx ??"
REM Käytetään ulkopuolista valikoimaa edellisen korvaamiseen, jos on tarjolla
IF NOT IsMissing(sValikoima) then sKielikoodit = sValikoima
'
iKnro = 1 + InStr(sKielikoodit,sKKoodi)/3 'Väleineen 3 merkkiä / kielikoodi!
REM Oletuskieli on nro 1. Nyt "fi", mutta on vaihdettavissa.
IF iKnro = 0 then
REM koodia ei ollut listalla, käytetään oletusta
iKieli = 1
else
iKieli = iKnro
EndIf
Virhe:
Resume Next
End Function 'Kieli
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|