<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Module: GetText</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" /> <script language="JavaScript" type="text/javascript"> // <![CDATA[ function toggleSource( id ) { var elem var link if( document.getElementById ) { elem = document.getElementById( id ) link = document.getElementById( "l_" + id ) } else if ( document.all ) { elem = eval( "document.all." + id ) link = eval( "document.all.l_" + id ) } else return false; if( elem.style.display == "block" ) { elem.style.display = "none" link.innerHTML = "show source" } else { elem.style.display = "block" link.innerHTML = "hide source" } } function openCode( url ) { window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" ) } // ]]> </script> </head> <body> <table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr> <td class="file-title"><span class="file-title-prefix">Module</span><br />GetText</td> <td align="right"> <table cellspacing=0 cellpadding=2> <tr valign="top"> <td>In:</td> <td> <a href="../files/lib/gettext/rmsgmerge_rb.html">lib/gettext/rmsgmerge.rb</a> <a href="../files/lib/gettext/poparser_rb.html">lib/gettext/poparser.rb</a> <a href="../files/lib/gettext/textdomainmanager_rb.html">lib/gettext/textdomainmanager.rb</a> <a href="../files/lib/gettext/container_rb.html">lib/gettext/container.rb</a> <a href="../files/lib/gettext/textdomain_rb.html">lib/gettext/textdomain.rb</a> <a href="../files/lib/gettext/rgettext_rb.html">lib/gettext/rgettext.rb</a> <a href="../files/lib/gettext/parser/activerecord_rb.html">lib/gettext/parser/activerecord.rb</a> <a href="../files/lib/gettext/parser/glade_rb.html">lib/gettext/parser/glade.rb</a> <a href="../files/lib/gettext/parser/ruby_rb.html">lib/gettext/parser/ruby.rb</a> <a href="../files/lib/gettext/parser/erb_rb.html">lib/gettext/parser/erb.rb</a> <a href="../files/lib/gettext/utils_rb.html">lib/gettext/utils.rb</a> <a href="../files/lib/gettext/version_rb.html">lib/gettext/version.rb</a> <a href="../files/lib/gettext/rmsgfmt_rb.html">lib/gettext/rmsgfmt.rb</a> <a href="../files/lib/gettext/rails_rb.html">lib/gettext/rails.rb</a> <a href="../files/lib/gettext/cgi_rb.html">lib/gettext/cgi.rb</a> <a href="../files/lib/gettext/erb_rb.html">lib/gettext/erb.rb</a> <a href="../files/lib/gettext_rb.html">lib/gettext.rb</a> </td> </tr> </table> </td> </tr> </table> <!-- banner header --> <div id="bodyContent"> <div id="content"> <div class="sectiontitle">Methods</div> <ul> <li><a href="#M000030">N_</a></li> <li><a href="#M000031">Nn_</a></li> <li><a href="#M000043">_</a></li> <li><a href="#M000040">add_default_locale_path</a></li> <li><a href="#M000026">bindtextdomain</a></li> <li><a href="#M000025">cgi</a></li> <li><a href="#M000024">cgi=</a></li> <li><a href="#M000020">create_mofiles</a></li> <li><a href="#M000041">current_textdomain_info</a></li> <li><a href="#M000028">gettext</a></li> <li><a href="#M000039">locale</a></li> <li><a href="#M000035">locale=</a></li> <li><a href="#M000019">msgmerge</a></li> <li><a href="#M000044">n_</a></li> <li><a href="#M000029">ngettext</a></li> <li><a href="#M000038">output_charset</a></li> <li><a href="#M000037">output_charset=</a></li> <li><a href="#M000018">rgettext</a></li> <li><a href="#M000022">rmsgfmt</a></li> <li><a href="#M000017">rmsgmerge</a></li> <li><a href="#M000045">s_</a></li> <li><a href="#M000023">set_cgi</a></li> <li><a href="#M000033">set_locale</a></li> <li><a href="#M000034">set_locale_all</a></li> <li><a href="#M000036">set_output_charset</a></li> <li><a href="#M000042">setlocale</a></li> <li><a href="#M000032">sgettext</a></li> <li><a href="#M000027">textdomain</a></li> <li><a href="#M000021">update_pofiles</a></li> </ul> <div class="sectiontitle">Classes and Modules</div> Module <a href="GetText/ActiveRecordParser.html" class="link">GetText::ActiveRecordParser</a><br /> Module <a href="GetText/ErbContainer.html" class="link">GetText::ErbContainer</a><br /> Module <a href="GetText/ErbParser.html" class="link">GetText::ErbParser</a><br /> Module <a href="GetText/GetText.html" class="link">GetText::GetText</a><br /> Module <a href="GetText/GladeParser.html" class="link">GetText::GladeParser</a><br /> Module <a href="GetText/Rails.html" class="link">GetText::Rails</a><br /> Module <a href="GetText/RubyParser.html" class="link">GetText::RubyParser</a><br /> Class <a href="GetText/NoboundTextDomainError.html" class="link">GetText::NoboundTextDomainError</a><br /> Class <a href="GetText/PoParser.html" class="link">GetText::PoParser</a><br /> Class <a href="GetText/TextDomain.html" class="link">GetText::TextDomain</a><br /> Class <a href="GetText/TextDomainManager.html" class="link">GetText::TextDomainManager</a><br /> <div class="sectiontitle">Constants</div> <table border='0' cellpadding='5'> <tr valign='top'> <td class="attr-name">VERSION</td> <td>=</td> <td class="attr-value">"1.7.0"</td> </tr> </table> <div class="sectiontitle">Public Instance methods</div> <div class="method"> <div class="title"> <a name="M000030"></a><b>N_</b>(msgid) [ <a href="javascript:openCode('GetText.src/M000030.html')">source</a> ] </div> <div class="description"> <p> This function does nothing. But it is required in order to recognize the msgid by rgettext. </p> <ul> <li>msgid: the message id. </li> <li>Returns: msgid. </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000031"></a><b>Nn_</b>(msgid, msgid_plural) [ <a href="javascript:openCode('GetText.src/M000031.html')">source</a> ] </div> <div class="description"> <p> This is same function as <a href="GetText.html#M000030">N_</a> but for ngettext. </p> <ul> <li>msgid: the message id. </li> <li>msgid_plural: the plural message id. </li> <li>Returns: msgid. </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000043"></a><b>_</b>(msgid) </div> <div class="description"> <p> Alias for <a href="GetText.html#M000028">gettext</a> </p> </div> </div> <div class="method"> <div class="title"> <a name="M000040"></a><b>add_default_locale_path</b>(path) [ <a href="javascript:openCode('GetText.src/M000040.html')">source</a> ] </div> <div class="description"> <p> Add default locale path. </p> <ul> <li>path: a new locale path. (e.g.) "/usr/share/locale/%{locale}/LC_MESSAGES/%{name}.mo" (‘locale’ => "ja_JP", ‘name’ => "textdomain") </li> <li>Returns: the new DEFAULT_LOCALE_PATHS </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000026"></a><b>bindtextdomain(domainname, options = {})<br /> </b> [ <a href="javascript:openCode('GetText.src/M000026.html')">source</a> ] </div> <div class="description"> <p> Bind a textdomain(%{path}/%{locale}/LC_MESSAGES/%{domainname}.mo) to your program. Normally, the texdomain scope becomes a ruby-script-file. So you need to call this function each ruby-script-files. On the other hand, if you call this function under GetText::Container (gettext/container, gettext/erb, gettext/rails), the textdomain scope becomes a Class/Module. </p> <ul> <li>domainname: the textdomain name. </li> <li>options: options as an Hash. <ul> <li>:path - the path to the mo-files. When the value is nil, it will search default paths such as /usr/share/locale, /usr/local/share/locale) </li> <li>:locale - the locale string such as "ja_JP.UTF-8". Generally, you should use <a href="GetText.html#M000033">GetText.set_locale</a> instead. The value is searched order by: the value of this value > System default language. </li> <li>:charset - output charset. This affect the current textdomain only. Generally, you should use <a href="GetText.html#M000036">GetText.set_output_charset</a> instead. The value is searched order by: the value of Locale.set_output_charset > ENV["OUTPUT_CHARSET"] > this value > System default charset. </li> </ul> </li> <li>Returns: the <a href="GetText/TextDomain.html">GetText::TextDomain</a>. </li> </ul> <p> Note: Don‘t use locale_, charset argument(not in options). They are remained for backward compatibility. </p> </div> </div> <div class="method"> <div class="title"> <a name="M000025"></a><b>cgi</b>() [ <a href="javascript:openCode('GetText.src/M000025.html')">source</a> ] </div> <div class="description"> <p> Gets the CGI object. If it is nil, returns new CGI object. </p> <ul> <li>Returns: the CGI object </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000024"></a><b>cgi=</b>(cgi_) [ <a href="javascript:openCode('GetText.src/M000024.html')">source</a> ] </div> <div class="description"> <p> Same as <a href="GetText.html#M000023">GetText.set_cgi</a>. </p> <ul> <li>cgi_: CGI object </li> <li>Returns: cgi_ </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000020"></a><b>create_mofiles</b>(verbose = false, podir = "./po", targetdir = "./data/locale", targetpath_rule = "%s/LC_MESSAGES") [ <a href="javascript:openCode('GetText.src/M000020.html')">source</a> ] </div> <div class="description"> <p> Creates mo-files using #{po_root}/#{lang}/*.po an put them to #{targetdir}/#{targetpath_rule}/. </p> <p> This is a convenience function of <a href="GetText.html#M000022">GetText.rmsgfmt</a> for plural target files. </p> <ul> <li>verbose: true if verbose mode, otherwise false </li> <li>po_root: the root directory of po-files. </li> <li>targetdir: the target root directory where the mo-files are stored. </li> <li>targetpath_rule: the target directory for each mo-files. "%s" becomes "#{lang}" under po_root. </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000041"></a><b>current_textdomain_info</b>(options = {}) [ <a href="javascript:openCode('GetText.src/M000041.html')">source</a> ] </div> <div class="description"> <p> Show the current textdomain information. This function is for debugging. </p> <ul> <li>options: options as a Hash. <ul> <li>:with_messages - show informations with messages of the current mo file. Default is false. </li> <li>:out - An output target. Default is STDOUT. </li> <li>:with_paths - show the load paths for mo-files. </li> </ul> </li> <li>Returns: localized text by msgid. If there are not binded mo-file, it will return msgid. </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000028"></a><b>gettext(msgid)<br /> _(msgid)<br /> </b> [ <a href="javascript:openCode('GetText.src/M000028.html')">source</a> ] </div> <div class="description"> <p> Translates msgid and return the message. </p> <ul> <li>msgid: the message id. </li> <li>Returns: localized text by msgid. If there are not binded mo-file, it will return msgid. </li> </ul> </div> <div class="aka"> This method is also aliased as <a href="GetText.html#M000043">_</a> </div> </div> <div class="method"> <div class="title"> <a name="M000039"></a><b>locale</b>() [ <a href="javascript:openCode('GetText.src/M000039.html')">source</a> ] </div> <div class="description"> <p> Gets the current locale. </p> <ul> <li>Returns: a current <a href="Locale/Object.html">Locale::Object</a> </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000035"></a><b>locale=</b>(locale) [ <a href="javascript:openCode('GetText.src/M000035.html')">source</a> ] </div> <div class="description"> <p> Same as <a href="GetText.html#M000033">GetText.set_locale</a>. </p> <ul> <li>locale: a locale string </li> <li>src: internal usage only. You shouldn’t use this. </li> <li>Returns: a locale string </li> </ul> </div> <div class="aka"> This method is also aliased as <a href="GetText.html#M000042">setlocale</a> </div> </div> <div class="method"> <div class="title"> <a name="M000019"></a><b>msgmerge</b>(defpo, refpo, app_version) [ <a href="javascript:openCode('GetText.src/M000019.html')">source</a> ] </div> <div class="description"> <p> Merges two Uniforum style .po files together. </p> <p> <b>Note</b> "msgmerge" tool is included in GNU <a href="GetText.html">GetText</a>. So you need to install GNU <a href="GetText.html">GetText</a>. </p> <p> The def.po file is an existing PO file with translations which will be taken over to the newly created file as long as they still match; comments will be preserved, but extracted comments and file positions will be discarded. </p> <p> The ref.pot file is the last created PO file with up-to-date source references but old translations, or a PO Template file (generally created by rgettext); any translations or comments in the file will be discarded, however dot comments and file positions will be preserved. Where an exact match cannot be found, fuzzy matching is used to produce better results. </p> <p> Usually you don’t need to call this function directly. Use <a href="GetText.html#M000021">GetText.update_pofiles</a> instead. </p> <ul> <li>defpo: a po-file. translations referring to old sources </li> <li>refpo: a po-file. references to new sources </li> <li>app_version: the application information which appears "Project-Id-Version: #{app_version}" in the pot/po-files. </li> <li>Returns: self </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000044"></a><b>n_</b>(arg1, arg2, arg3 = nil) </div> <div class="description"> <p> Alias for <a href="GetText.html#M000029">ngettext</a> </p> </div> </div> <div class="method"> <div class="title"> <a name="M000029"></a><b>ngettext(msgid, msgid_plural, n)<br /> ngettext(msgids, n) # msgids = [msgid, msgid_plural]<br /> n_(msgid, msgid_plural, n)<br /> n_(msgids, n) # msgids = [msgid, msgid_plural]<br /> </b> [ <a href="javascript:openCode('GetText.src/M000029.html')">source</a> ] </div> <div class="description"> <p> The ngettext is similar to the gettext function as it finds the message catalogs in the same way. But it takes two extra arguments for plural form. </p> <ul> <li>msgid: the singular form. </li> <li>msgid_plural: the plural form. </li> <li>n: a number used to determine the plural form. </li> <li>Returns: the localized text which key is msgid_plural if n is plural(follow plural-rule) or msgid. "plural-rule" is defined in po-file. </li> </ul> </div> <div class="aka"> This method is also aliased as <a href="GetText.html#M000044">n_</a> </div> </div> <div class="method"> <div class="title"> <a name="M000038"></a><b>output_charset</b>() [ <a href="javascript:openCode('GetText.src/M000038.html')">source</a> ] </div> <div class="description"> <p> Gets the current <a href="GetText.html#M000038">output_charset</a> which is set using <a href="GetText.html#M000036">GetText.set_output_charset</a>. </p> <ul> <li>Returns: <a href="GetText.html#M000038">output_charset</a>. </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000037"></a><b>output_charset=</b>(charset) [ <a href="javascript:openCode('GetText.src/M000037.html')">source</a> ] </div> <div class="description"> <p> Same as <a href="GetText.html#M000036">GetText.set_output_charset</a> </p> <ul> <li>charset: an <a href="GetText.html#M000038">output_charset</a> </li> <li>Returns: charset </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000018"></a><b>rgettext</b>(targetfiles = nil, out = STDOUT) [ <a href="javascript:openCode('GetText.src/M000018.html')">source</a> ] </div> <div class="description"> <p> Creates a po-file from targetfiles(ruby-script-files, ActiveRecord, .rhtml files, glade-2 XML files), then output the result to out. If no parameter is set, it behaves same as command line tools(rgettet). </p> <p> This function is a part of GetText.create_pofiles. Usually you don’t need to call this function directly. </p> <p> <b>Note</b> for ActiveRecord, you need to run your database server and configure the config/database.xml correctly before execute this function. </p> <ul> <li>targetfiles: An Array of po-files or nil. </li> <li>out: output IO or output path. </li> <li>Returns: self </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000022"></a><b>rmsgfmt</b>(targetfile = nil, output_path = nil) [ <a href="javascript:openCode('GetText.src/M000022.html')">source</a> ] </div> <div class="description"> <p> Creates a mo-file from a targetfile(po-file), then output the result to out. If no parameter is set, it behaves same as command line tools(rmsgfmt). </p> <ul> <li>targetfile: An Array of po-files or nil. </li> <li>output_path: output path. </li> <li>Returns: the <a href="MOFile.html">MOFile</a> object. </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000017"></a><b>rmsgmerge</b>(reference = nil, definition = nil, out = STDOUT) [ <a href="javascript:openCode('GetText.src/M000017.html')">source</a> ] </div> <div class="description"> <p> Experimental </p> </div> </div> <div class="method"> <div class="title"> <a name="M000045"></a><b>s_</b>(msgid, div = '|') </div> <div class="description"> <p> Alias for <a href="GetText.html#M000032">sgettext</a> </p> </div> </div> <div class="method"> <div class="title"> <a name="M000023"></a><b>set_cgi</b>(cgi_) [ <a href="javascript:openCode('GetText.src/M000023.html')">source</a> ] </div> <div class="description"> <p> Sets a CGI object. </p> <ul> <li>cgi_: CGI object </li> <li>Returns: self </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000033"></a><b>set_locale</b>(locale, this_target_only = false) [ <a href="javascript:openCode('GetText.src/M000033.html')">source</a> ] </div> <div class="description"> <p> Sets locale to the current class/module </p> <p> Notice that you shouldn’t use this for your own Libraries. </p> <ul> <li>locale: a locale string or <a href="Locale/Object.html">Locale::Object</a>. </li> <li>this_target_only: true if you want to change the current class/module only. </li> </ul> <p> Otherwise, this changes the locale of the current class/module and its ancestors. Default is false. </p> <ul> <li>Returns: self </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000034"></a><b>set_locale_all</b>(locale) [ <a href="javascript:openCode('GetText.src/M000034.html')">source</a> ] </div> <div class="description"> <p> Sets locale to the all textdomains. </p> <p> Notice that you shouldn’t use this for your own Libraries. </p> <ul> <li>locale: a locale string or <a href="Locale/Object.html">Locale::Object</a>. </li> <li>Returns: self </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000036"></a><b>set_output_charset</b>(charset) [ <a href="javascript:openCode('GetText.src/M000036.html')">source</a> ] </div> <div class="description"> <p> Sets charset(<a href="String.html">String</a>) such as "euc-jp", "sjis", "CP932", "utf-8", … You shouldn’t use this in your own Libraries. </p> <ul> <li>charset: an <a href="GetText.html#M000038">output_charset</a> </li> <li>Returns: charset </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000042"></a><b>setlocale</b>(locale) </div> <div class="description"> <p> Alias for <a href="GetText.html#M000035">locale=</a> </p> </div> </div> <div class="method"> <div class="title"> <a name="M000032"></a><b>sgettext(msgid, div = '|')<br /> s_(msgid, div = '|')<br /> </b> [ <a href="javascript:openCode('GetText.src/M000032.html')">source</a> ] </div> <div class="description"> <p> Translates msgid, but if there are no localized text, it returns a last part of msgid separeted "div". </p> <ul> <li>msgid: the message id. </li> <li>div: separator or nil. </li> <li>Returns: the localized text by msgid. If there are no localized text, it returns a last part of msgid separeted "div". </li> </ul> <p> See: <a href="http://www.gnu.org/software/gettext/manual/html_mono/gettext.html#SEC151">www.gnu.org/software/gettext/manual/html_mono/gettext.html#SEC151</a> </p> </div> <div class="aka"> This method is also aliased as <a href="GetText.html#M000045">s_</a> </div> </div> <div class="method"> <div class="title"> <a name="M000027"></a><b>textdomain</b>(domainname) [ <a href="javascript:openCode('GetText.src/M000027.html')">source</a> ] </div> <div class="description"> <p> Binds a existed textdomain to your program. This is the same function with <a href="GetText.html#M000026">GetText.bindtextdomain</a> but simpler than bindtextdomain. Notice that you need to call <a href="GetText.html#M000026">GetText.bindtextdomain</a> first. If the domainname hasn’t bound yet, raises <a href="GetText/NoboundTextDomainError.html">GetText::NoboundTextDomainError</a>. </p> <ul> <li>domainname: a textdomain name. </li> <li>Returns: the <a href="GetText/TextDomain.html">GetText::TextDomain</a>. </li> </ul> </div> </div> <div class="method"> <div class="title"> <a name="M000021"></a><b>update_pofiles</b>(textdomain, files, app_version, po_root = "po", refpot = "tmp.pot") [ <a href="javascript:openCode('GetText.src/M000021.html')">source</a> ] </div> <div class="description"> <p> At first, this creates the #{po_root}/#{domainname}.pot file using <a href="GetText.html#M000018">GetText.rgettext</a>. Since 2nd time, this updates(merges) the #{po_root}/#{domainname}.pot and all of the #{po_root}/#{lang}/#{domainname}.po files under "po_root" using "msgmerge". </p> <p> <b>Note</b> "msgmerge" tool is included in GNU <a href="GetText.html">GetText</a>. So you need to install GNU <a href="GetText.html">GetText</a>. </p> <p> See <HOWTO maintain po/mo files(<a href="http://www.yotabanana.com/hiki/ruby-gettext-howto-manage.html">www.yotabanana.com/hiki/ruby-gettext-howto-manage.html</a>)> for more detals. </p> <ul> <li>domainname: the textdomain name. </li> <li>targetfiles: An Array of target files or nil (See <a href="GetText.html#M000018">GetText.rgettext</a> for more details). </li> <li>app_version: the application information which appears "Project-Id-Version: #{app_version}" in the pot/po-files. </li> <li>po_root: the root directory of po-files. </li> <li>refpot: set the temporary file name. You shouldn’t use this(It will be removed). </li> </ul> <pre> (e.g.) GetText.update_pofiles("myapp", Dir.glob("lib/*.rb"), "myapp 1.0.0") </pre> </div> </div> </div> </div> </body> </html>