ScriptForge.L10N zerbitzua

Zerbitzu honek kateak itzultzeko balio duten metodoak eskaintzen ditu, eta inpaktu oso txikia du programaren iturburu-kodean. L10N zerbitzuak eskaintzen dituen metodoak hurrengoetarako erabili daitezke batez ere:

note

L10N akronimoak lokalizazioa adierazten du, eta softwarea eskualde edo herrialde jakin bateko hizkuntzara itzultzeko erabiltzen diren prozedura multzoari egiten dio erreferentzia.


PO fitxategiak software librearen komunitatean erabiltzaile-interfaze eleaniztunak eskaintzeko modu bat dira. Horretarako, gizakiak irakurtzeko moduko testu-fitxategiak erabiltzen dira, egitura ongi definitua dutenak eta, edozein hizkuntzatarako, iturburuko hizkuntza-katea eta itzulitako katea zehazten dituztenak.

PO formatuaren abantaila nagusia da programatzailea eta itzultzailea bereizten dituela. PO fitxategiak testu-fitxategi independenteak dira: programatzaileak POT txantiloiak bidaliko dizkio itzultzaileari, azken horrek fitxategiaren edukiak itzuliko ditu eta hizkuntza bakoitzerako itzulitako PO fitxategiak programatzaileari bidaliko dizkio.

tip

L10N zerbitzua PO (portable object) fitxategien GNU inplementazioan dago oinarrituta. Fitxategi-formatu hori hobeto ezagutzeko, begiratu GNU gettext Utilities: PO Files informazioa.


This service implements the methods listed below:

note

Ikusi nola lehen bi metodoak kate itzulgarrien multzo bat eraikitzeko eta haiek POT fitxategi batera esportatzeko erabiltzen diren. Hala ere, ez da derrigorrezkoa POT fitxategiak sortzea metodo horiek erabilita. testu-fitxategiak direnez gero, programatzaileak edozein testu-editore erabilita sortu ditzake.


Zerbitzuari deitzea

L10N zerbitzuari deitzeko, aukerako bi argumentu zehaztu daitezke PO fitxategiak zein karpetatan dauden eta erabiliko den hizkuntza adierazteko, behean deskribatzen den moduan.

Sintaxia:

CreateScriptService("L10N", foldername: str, locale: str): svc

foldername: The folder containing the PO files. It must be expressed in the FileSystem.FileNaming notation.

locale: A string in the form "la-CO" (language-COUNTRY) or in the form "la" (language) only.

note

L10N zerbitzuaren instantzia anitz bizi daitezke elkarrekin. Hala ere, instantzia bakoitzak bere direktorio propioa erabili behar du bere PO fitxategietarako.


Adibidea:

Basic lengoaian

Hurrengo adibidean, L10N zerbitzuaren instantzia bat aukerako argumenturik gabe sortu da. Horrela, AddText eta ExportToPOTFile metodoak soilik gaituko dira.


      GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
      Dim myPO As Variant
      Set myPO = CreateScriptService("L10N")
    

Beheko adibidean, PO fitxategiak dituen karpeta zehaztu da. Hizkuntza ez dagoenez definituta, zerbitzu-instantziak uneko LibreOffice ezarpenetan ezarritako hizkuntza erabiliko du.


      Set myPO = CreateScriptService("L10N", "C:\myPOFiles")
    
warning

The example above will result in an runtime error if the PO file for the current locale does not exist in the specified folder.


Beheko adibidean, bai karpetaren izena bai hizkuntza-ezarpenak Espainiako euskararenak direla definitu da esplizituki.


      Set myPO = CreateScriptService("L10N", "C:\myPOFiles", "fr-BE")
    
Iradokizun-ikonoa

PO fitxategiak "la-CO.po" edo "la.po" forman izendatu behar dira, non "la" hizkuntza den eta "CO" herrialdea den. Zenbait adibide: "en-US.po", "eu-FR.po" edo "eu.po".


Gomendagarria da baliabideak askatzea haiek erabili ondoren:


      Set myPO = myPO.Dispose()
    
Python lengoaian

The examples above can be translated to Python as follows:


      from scriptforge import CreateScriptService
      myPO = CreateScriptService('L10N')
    

      myPO = CreateScriptService('L10N', r'C:\myPOFiles')
    

      myPO = CreateScriptService('L10N', r'C:\myPOFiles', 'fr-BE')
      myPO = myPO.Dispose()
    

Propietateak

Izena

Irakurtzeko soilik

Mota

Deskribapena

Folder

Bai

String

PO fitxategiak dituen karpeta (begiratu FileSystem.FileNaming propietatea hemen erabilitako notazioa ikasteko).

Languages

Bai

Array

Zehaztutako Folder karpetan dauden PO fitxategien oinarri-izen guztiak (".po" luzapenik gabe) zerrendatzen dituen zeron oinarritutako matrize bat.

Locale

Bai

String

Unean aktiboa den hizkuntza-HERRIALDEA konbinazioa. Propietate hori hasieran hutsik egongo da zerbitzuak aukerako argumenturik gabe instantziatu bada.


L10N zerbitzuaren metodoen zerrenda

AddText
AddTextsFromDialog

ExportToPOTFile

GetText


AddText

Beste sarrera bat gehitzen dio kate itzulgarrien zerrendari. Ez du lehendik existitu behar.

The method returns True if successful.

Sintaxia:

svc.AddText(context: str = '', msgid: str = '', comment: str = ''): bool

Parametroak:

context: The key to retrieve the translated string with the GetText method. This parameter has a default value of "".

msgid: The untranslated string, which is the text appearing in the program code. It must not be empty. The msgid becomes the key to retrieve the translated string via GetText method when context is empty.

The msgid string may contain any number of placeholders (%1 %2 %3 ...) for dynamically modifying the string at runtime.

comment: Optional comment to be added alongside the string to help translators.

Adibidea:

Beheko adibideak ingelesezko kate multzo bat sortzen du:

Basic lengoaian

      myPO.AddText(, "This is a string to be included in a POT file")
      myPO.AddText("CTX1", "A string with a context")
      myPO.AddText(, "Provide a String value", Comment := "Do not translate the word String")
    
Python lengoaian

      myPO.AddText(msgid = 'This is a string to be included in a POT file')
      myPO.AddText('CTX1', 'A string with a context')
      myPO.AddText(msgid = 'Provide a String value', comment = 'Do not translate the word String')
    

AddTextsFromDialog

Automatically extracts strings from a dialog and adds them to the list of localizable text strings. The following strings are extracted:

The method returns True if successful.

note

The dialog from which strings will be extracted must not be open when the method is called.


When a L10N service instance is created from an existing PO file, use the GetTextsFromL10N method from the Dialog service to automatically load all translated strings into the dialog.

Sintaxia:

svc.AddTextsFromDialog(dialog: svc): bool

Parametroak:

dialog: a Dialog service instance corresponding to the dialog from which strings will be extracted.

Adibidea:

The following example extracts all strings from the dialog "MyDialog" stored in the "Standard" library and exports them to a POT file:

Basic lengoaian

      oDlg = CreateScriptService("Dialog", "GlobalScope", "Standard", "MyDialog")
      myPO = CreateScriptService("L10N")
      myPO.AddTextsFromDialog(oDlg)
      myPO.ExportToPOTFile("en-US.pot")
    
Python lengoaian

      dlg = CreateScriptService("Dialog", "GlobalScope", "Standard", "Dialog1")
      myPO = CreateScriptService("L10N")
      myPO.AddTextsFromDialog(dlg)
      myPO.ExportToPOTFile("en-US.pot")
    

ExportToPOTFile

Itzuli gabeko kateen multzo bat POT fitxategi modura esportatzen du.

To build a set of strings you can use either a succession of AddText method calls, or by a successful invocation of the L10N service with the foldername argument present. It is also possible to use a combination of both techniques.

The method returns True if successful.

Sintaxia:

svc.ExportToPOTFile(filename: str, header: str = '', encoding:str = 'UTF-8'): bool

Parametroak:

filename: The output file in FileSystem.FileNaming notation.

header: Comments that will be added on top of the generated POT file.

Do not include any leading "#" characters. If you want the header to be broken into multiple lines, insert escape sequences (\n) where relevant. A standard header will be added alongside the text specified in the header argument.

encoding: The character set to be used (Default = "UTF-8").

Adibidea:


       ' Basic
       myPO.ExportToPOTFile("myFile.pot", Header := "First line of the header\nSecond line of the header")
    

      # Python
      myPO.ExportToPOTFile('myFile.pot', header = 'First line of the header\nSecond line of the header')
    
note

Sortutako fitxategiak msgfmt --check GNU komandoa ongi gainditu behar du.


GetText

Gets the translated string corresponding to the given msgid argument.

Argumentuen zerrenda bat zehaztu daiteke kateko leku-markak (%1, %2, ...) ordezteko.

Itzulitako katerik aurkitzen ez bada, metodoak itzuli gabeko katea itzuliko du, leku-marken ordez zehaztutako argumentuak jarrita.

Sintaxia:

Metodo horri deitzeko, erabili GetText edo _ (azpimarra bakarra) lasterbidea:

svc.GetText(msgid: str, args: any[0..*]): str

svc._(msgid: str, args: any[0..*]): str

note

In the ScriptForge library, all methods starting with the "_" character are reserved for internal use only. However, the shortcut _ used for GetText is the only exception to this rule, hence it can be safely used in Basic and Python scripts.


Parametroak:

msgid: The untranslated string, which is the text appearing in the program code. It must not be empty. It may contain any number of placeholders (%1 %2 %3 ...) that can be used to dynamically insert text at runtime.

Besides using a single msgid string, this method also accepts the following formats:

args: Values to be inserted into the placeholders. Any variable type is allowed, however only strings, numbers and dates will be considered.

Adibidea:

Basic lengoaian

Adibidez, LibreOffice instalazio baten hizkuntza "es-ES" dela ezarrita badago eta, horrez gain, zehaztutako karpetaren barruan GetText metodoak pasatutako katea itzultzen duen "es-ES.po" fitxategi bat badago, kodea honelakoa litzateke:


      myPO = CreateScriptService("L10N", "C:\myPOFiles\")
      myPO.GetText("Welcome %1! Hope you enjoy this program", "John")
      ' "¡Bienvenido John! Espero que disfrutes de este programa"
    
Python lengoaian

      myPO = CreateScriptService('L10N', r"C:\myPOFiles")
      myPO.GetText('Welcome %1! Hope you enjoy this program', 'John')
      # "¡Bienvenido John! Espero que disfrutes de este programa"
    
warning

Azpimarraren karaktere bat, "_", aurrizki gisa duten ScriptForge Basic errutina edo identifikatzaile guztiak barneko erabilerarako erreserbatuta daude. Ez dira Basic makroetan edo Python scriptetan erabili behar.