Gloc plugin upgraded to 1.2.0.
git-svn-id: http://redmine.rubyforge.org/svn/branches/work@1391 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
1 parent
867b206e85
commit
35bac0d003
62 files changed
+1087
-5287
No files matched your search
-19
@@ -1,19 +0,0 @@
|
|||||||
== Version 1.1 (28 May 2006)
|
|
||||||
|
|
||||||
* The charset for each and/or all languages can now be easily configured.
|
|
||||||
* Added a ActionController filter that auto-detects the client language.
|
|
||||||
* The rake task "sort" now merges lines that match 100%, and warns if duplicate keys are found.
|
|
||||||
* Rule support. Create flexible rules to handle issues such as pluralization.
|
|
||||||
* Massive speed and stability improvements to development mode.
|
|
||||||
* Added Russian strings. (Thanks to Evgeny Lineytsev)
|
|
||||||
* Complete RDoc documentation.
|
|
||||||
* Improved helpers.
|
|
||||||
* GLoc now configurable via get_config and set_config
|
|
||||||
* Added an option to tell GLoc to output various verbose information.
|
|
||||||
* More useful functions such as set_language_if_valid, similar_language
|
|
||||||
* GLoc's entire internal state can now be backed up and restored.
|
|
||||||
|
|
||||||
|
|
||||||
== Version 1.0 (17 April 2006)
|
|
||||||
|
|
||||||
* Initial public release.
|
|
||||||
Vendored
-230
@@ -1,230 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Module: ActionController::Filters::ClassMethods</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="classHeader">
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Module</strong></td>
|
|
||||||
<td class="class-name-in-header">ActionController::Filters::ClassMethods</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>In:</strong></td>
|
|
||||||
<td>
|
|
||||||
<a href="../../../files/lib/gloc-rails_rb.html">
|
|
||||||
lib/gloc-rails.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-list">
|
|
||||||
<h3 class="section-bar">Methods</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<a href="#M000001">autodetect_language_filter</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
<div id="methods">
|
|
||||||
<h3 class="section-bar">Public Instance methods</h3>
|
|
||||||
|
|
||||||
<div id="method-M000001" class="method-detail">
|
|
||||||
<a name="M000001"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000001" class="method-signature">
|
|
||||||
<span class="method-name">autodetect_language_filter</span><span class="method-args">(*args)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
This filter attempts to auto-detect the clients desired language. It first
|
|
||||||
checks the params, then a cookie and then the HTTP_ACCEPT_LANGUAGE request
|
|
||||||
header. If a language is found to match or be similar to a currently valid
|
|
||||||
language, then it sets the current_language of the controller.
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
class ExampleController < ApplicationController
|
|
||||||
set_language :en
|
|
||||||
autodetect_language_filter :except => 'monkey', :on_no_lang => :lang_not_autodetected_callback
|
|
||||||
autodetect_language_filter :only => 'monkey', :check_cookie => 'monkey_lang', :check_accept_header => false
|
|
||||||
...
|
|
||||||
def lang_not_autodetected_callback
|
|
||||||
redirect_to somewhere
|
|
||||||
end
|
|
||||||
end
|
|
||||||
</pre>
|
|
||||||
<p>
|
|
||||||
The <tt>args</tt> for this filter are exactly the same the arguments of
|
|
||||||
<tt>before_filter</tt> with the following exceptions:
|
|
||||||
</p>
|
|
||||||
<ul>
|
|
||||||
<li><tt>:check_params</tt> — If false, then params will not be checked
|
|
||||||
for a language. If a String, then this will value will be used as the name
|
|
||||||
of the param.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li><tt>:check_cookie</tt> — If false, then the cookie will not be
|
|
||||||
checked for a language. If a String, then this will value will be used as
|
|
||||||
the name of the cookie.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li><tt>:check_accept_header</tt> — If false, then HTTP_ACCEPT_LANGUAGE
|
|
||||||
will not be checked for a language.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li><tt>:on_set_lang</tt> — You can specify the name of a callback
|
|
||||||
function to be called when the language is successfully detected and set.
|
|
||||||
The param must be a Symbol or a String which is the name of the function.
|
|
||||||
The callback function must accept one argument (the language) and must be
|
|
||||||
instance level.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li><tt>:on_no_lang</tt> — You can specify the name of a callback
|
|
||||||
function to be called when the language couldn’t be detected
|
|
||||||
automatically. The param must be a Symbol or a String which is the name of
|
|
||||||
the function. The callback function must be instance level.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<p>
|
|
||||||
You override the default names of the param or cookie by calling <tt><a
|
|
||||||
href="../../GLoc.html#M000014">GLoc.set_config</a> :default_param_name
|
|
||||||
=> ‘new_param_name‘</tt> and <tt><a
|
|
||||||
href="../../GLoc.html#M000014">GLoc.set_config</a> :default_cookie_name
|
|
||||||
=> ‘new_cookie_name‘</tt>.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000001-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-rails.rb, line 43</span>
|
|
||||||
43: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">autodetect_language_filter</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
|
||||||
44: <span class="ruby-identifier">options</span>= <span class="ruby-identifier">args</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">last</span> <span class="ruby-operator">:</span> {}
|
|
||||||
45: <span class="ruby-identifier">x</span>= <span class="ruby-value str">'Proc.new { |c| l= nil;'</span>
|
|
||||||
46: <span class="ruby-comment cmt"># :check_params</span>
|
|
||||||
47: <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">v</span>= <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:check_params</span>)) <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span>
|
|
||||||
48: <span class="ruby-identifier">name</span>= <span class="ruby-identifier">v</span> <span class="ruby-value">? </span><span class="ruby-node">":#{v}"</span> <span class="ruby-operator">:</span> <span class="ruby-value str">'GLoc.get_config(:default_param_name)'</span>
|
|
||||||
49: <span class="ruby-identifier">x</span> <span class="ruby-operator"><<</span> <span class="ruby-node">"l ||= GLoc.similar_language(c.params[#{name}]);"</span>
|
|
||||||
50: <span class="ruby-keyword kw">end</span>
|
|
||||||
51: <span class="ruby-comment cmt"># :check_cookie</span>
|
|
||||||
52: <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">v</span>= <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:check_cookie</span>)) <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span>
|
|
||||||
53: <span class="ruby-identifier">name</span>= <span class="ruby-identifier">v</span> <span class="ruby-value">? </span><span class="ruby-node">":#{v}"</span> <span class="ruby-operator">:</span> <span class="ruby-value str">'GLoc.get_config(:default_cookie_name)'</span>
|
|
||||||
54: <span class="ruby-identifier">x</span> <span class="ruby-operator"><<</span> <span class="ruby-node">"l ||= GLoc.similar_language(c.send(:cookies)[#{name}]);"</span>
|
|
||||||
55: <span class="ruby-keyword kw">end</span>
|
|
||||||
56: <span class="ruby-comment cmt"># :check_accept_header</span>
|
|
||||||
57: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:check_accept_header</span>) <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span>
|
|
||||||
58: <span class="ruby-identifier">x</span> <span class="ruby-operator"><<</span> <span class="ruby-value str">%<
|
|
||||||
59: unless l
|
|
||||||
60: a= c.request.env['HTTP_ACCEPT_LANGUAGE'].split(/,|;/) rescue nil
|
|
||||||
61: a.each {|x| l ||= GLoc.similar_language(x)} if a
|
|
||||||
62: end; ></span>
|
|
||||||
63: <span class="ruby-keyword kw">end</span>
|
|
||||||
64: <span class="ruby-comment cmt"># Set language</span>
|
|
||||||
65: <span class="ruby-identifier">x</span> <span class="ruby-operator"><<</span> <span class="ruby-value str">'ret= true;'</span>
|
|
||||||
66: <span class="ruby-identifier">x</span> <span class="ruby-operator"><<</span> <span class="ruby-value str">'if l; c.set_language(l); c.headers[\'Content-Language\']= l.to_s; '</span>
|
|
||||||
67: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:on_set_lang</span>)
|
|
||||||
68: <span class="ruby-identifier">x</span> <span class="ruby-operator"><<</span> <span class="ruby-node">"ret= c.#{options.delete(:on_set_lang)}(l);"</span>
|
|
||||||
69: <span class="ruby-keyword kw">end</span>
|
|
||||||
70: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:on_no_lang</span>)
|
|
||||||
71: <span class="ruby-identifier">x</span> <span class="ruby-operator"><<</span> <span class="ruby-node">"else; ret= c.#{options.delete(:on_no_lang)};"</span>
|
|
||||||
72: <span class="ruby-keyword kw">end</span>
|
|
||||||
73: <span class="ruby-identifier">x</span> <span class="ruby-operator"><<</span> <span class="ruby-value str">'end; ret }'</span>
|
|
||||||
74:
|
|
||||||
75: <span class="ruby-comment cmt"># Create filter</span>
|
|
||||||
76: <span class="ruby-identifier">block</span>= <span class="ruby-identifier">eval</span> <span class="ruby-identifier">x</span>
|
|
||||||
77: <span class="ruby-identifier">before_filter</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
|
||||||
78: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Class: ActionMailer::Base</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="classHeader">
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Class</strong></td>
|
|
||||||
<td class="class-name-in-header">ActionMailer::Base</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>In:</strong></td>
|
|
||||||
<td>
|
|
||||||
<a href="../../files/lib/gloc-rails_rb.html">
|
|
||||||
lib/gloc-rails.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Parent:</strong></td>
|
|
||||||
<td>
|
|
||||||
Object
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
In addition to including <a href="../GLoc.html">GLoc</a>,
|
|
||||||
<tt>render_message</tt> is also overridden so that mail templates contain
|
|
||||||
the current language at the end of the file. Eg. <tt>deliver_hello</tt>
|
|
||||||
will render <tt>hello_en.rhtml</tt>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
<div id="includes">
|
|
||||||
<h3 class="section-bar">Included Modules</h3>
|
|
||||||
|
|
||||||
<div id="includes-list">
|
|
||||||
<span class="include-name"><a href="../GLoc.html">GLoc</a></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="aliases-list">
|
|
||||||
<h3 class="section-bar">External Aliases</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<table summary="aliases">
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">render_message</td>
|
|
||||||
<td>-></td>
|
|
||||||
<td class="context-item-value">render_message_without_gloc</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,174 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Class: ActionView::Base</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="classHeader">
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Class</strong></td>
|
|
||||||
<td class="class-name-in-header">ActionView::Base</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>In:</strong></td>
|
|
||||||
<td>
|
|
||||||
<a href="../../files/lib/gloc-rails_rb.html">
|
|
||||||
lib/gloc-rails.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Parent:</strong></td>
|
|
||||||
<td>
|
|
||||||
Object
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
<tt>initialize</tt> is overridden so that new instances of this class
|
|
||||||
inherit the current language of the controller.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-list">
|
|
||||||
<h3 class="section-bar">Methods</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<a href="#M000046">new</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
<div id="includes">
|
|
||||||
<h3 class="section-bar">Included Modules</h3>
|
|
||||||
|
|
||||||
<div id="includes-list">
|
|
||||||
<span class="include-name"><a href="../GLoc.html">GLoc</a></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="aliases-list">
|
|
||||||
<h3 class="section-bar">External Aliases</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<table summary="aliases">
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">initialize</td>
|
|
||||||
<td>-></td>
|
|
||||||
<td class="context-item-value">initialize_without_gloc</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
<div id="methods">
|
|
||||||
<h3 class="section-bar">Public Class methods</h3>
|
|
||||||
|
|
||||||
<div id="method-M000046" class="method-detail">
|
|
||||||
<a name="M000046"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000046" class="method-signature">
|
|
||||||
<span class="method-name">new</span><span class="method-args">(base_path = nil, assigns_for_first_render = {}, controller = nil)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000046-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-rails.rb, line 109</span>
|
|
||||||
109: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">base_path</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">assigns_for_first_render</span> = {}, <span class="ruby-identifier">controller</span> = <span class="ruby-keyword kw">nil</span>)
|
|
||||||
110: <span class="ruby-identifier">initialize_without_gloc</span>(<span class="ruby-identifier">base_path</span>, <span class="ruby-identifier">assigns_for_first_render</span>, <span class="ruby-identifier">controller</span>)
|
|
||||||
111: <span class="ruby-identifier">set_language</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">current_language</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">nil?</span>
|
|
||||||
112: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
-348
@@ -1,348 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Module: ActionView::Helpers::DateHelper</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="classHeader">
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Module</strong></td>
|
|
||||||
<td class="class-name-in-header">ActionView::Helpers::DateHelper</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>In:</strong></td>
|
|
||||||
<td>
|
|
||||||
<a href="../../../files/lib/gloc-rails-text_rb.html">
|
|
||||||
lib/gloc-rails-text.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-list">
|
|
||||||
<h3 class="section-bar">Methods</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<a href="#M000041">distance_of_time_in_words</a>
|
|
||||||
<a href="#M000042">select_day</a>
|
|
||||||
<a href="#M000043">select_month</a>
|
|
||||||
<a href="#M000044">select_year</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
<div id="constants-list">
|
|
||||||
<h3 class="section-bar">Constants</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<table summary="Constants">
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">LOCALIZED_HELPERS</td>
|
|
||||||
<td>=</td>
|
|
||||||
<td class="context-item-value">true</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">LOCALIZED_MONTHNAMES</td>
|
|
||||||
<td>=</td>
|
|
||||||
<td class="context-item-value">{}</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">LOCALIZED_ABBR_MONTHNAMES</td>
|
|
||||||
<td>=</td>
|
|
||||||
<td class="context-item-value">{}</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
<div id="methods">
|
|
||||||
<h3 class="section-bar">Public Instance methods</h3>
|
|
||||||
|
|
||||||
<div id="method-M000041" class="method-detail">
|
|
||||||
<a name="M000041"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000041" class="method-signature">
|
|
||||||
<span class="method-name">distance_of_time_in_words</span><span class="method-args">(from_time, to_time = 0, include_seconds = false)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
This method uses <tt>current_language</tt> to return a localized string.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000041-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-rails-text.rb, line 16</span>
|
|
||||||
16: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">to_time</span> = <span class="ruby-value">0</span>, <span class="ruby-identifier">include_seconds</span> = <span class="ruby-keyword kw">false</span>)
|
|
||||||
17: <span class="ruby-identifier">from_time</span> = <span class="ruby-identifier">from_time</span>.<span class="ruby-identifier">to_time</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">from_time</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_time</span>)
|
|
||||||
18: <span class="ruby-identifier">to_time</span> = <span class="ruby-identifier">to_time</span>.<span class="ruby-identifier">to_time</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">to_time</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_time</span>)
|
|
||||||
19: <span class="ruby-identifier">distance_in_minutes</span> = (((<span class="ruby-identifier">to_time</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">from_time</span>).<span class="ruby-identifier">abs</span>)<span class="ruby-operator">/</span><span class="ruby-value">60</span>).<span class="ruby-identifier">round</span>
|
|
||||||
20: <span class="ruby-identifier">distance_in_seconds</span> = ((<span class="ruby-identifier">to_time</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">from_time</span>).<span class="ruby-identifier">abs</span>).<span class="ruby-identifier">round</span>
|
|
||||||
21:
|
|
||||||
22: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">distance_in_minutes</span>
|
|
||||||
23: <span class="ruby-keyword kw">when</span> <span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">1</span>
|
|
||||||
24: <span class="ruby-keyword kw">return</span> (<span class="ruby-identifier">distance_in_minutes</span><span class="ruby-operator">==</span><span class="ruby-value">0</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">l</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_minute_less_than</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">l</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_minute_single</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">include_seconds</span>
|
|
||||||
25: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">distance_in_seconds</span>
|
|
||||||
26: <span class="ruby-keyword kw">when</span> <span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">5</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">lwr</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_second_less_than</span>, <span class="ruby-value">5</span>)
|
|
||||||
27: <span class="ruby-keyword kw">when</span> <span class="ruby-value">6</span><span class="ruby-operator">..</span><span class="ruby-value">10</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">lwr</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_second_less_than</span>, <span class="ruby-value">10</span>)
|
|
||||||
28: <span class="ruby-keyword kw">when</span> <span class="ruby-value">11</span><span class="ruby-operator">..</span><span class="ruby-value">20</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">lwr</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_second_less_than</span>, <span class="ruby-value">20</span>)
|
|
||||||
29: <span class="ruby-keyword kw">when</span> <span class="ruby-value">21</span><span class="ruby-operator">..</span><span class="ruby-value">40</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">l</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_minute_half</span>)
|
|
||||||
30: <span class="ruby-keyword kw">when</span> <span class="ruby-value">41</span><span class="ruby-operator">..</span><span class="ruby-value">59</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">l</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_minute_less_than</span>)
|
|
||||||
31: <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">l</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_minute</span>)
|
|
||||||
32: <span class="ruby-keyword kw">end</span>
|
|
||||||
33:
|
|
||||||
34: <span class="ruby-keyword kw">when</span> <span class="ruby-value">2</span><span class="ruby-operator">..</span><span class="ruby-value">45</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">lwr</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_minute</span>, <span class="ruby-identifier">distance_in_minutes</span>)
|
|
||||||
35: <span class="ruby-keyword kw">when</span> <span class="ruby-value">46</span><span class="ruby-operator">..</span><span class="ruby-value">90</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">l</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_hour_about_single</span>)
|
|
||||||
36: <span class="ruby-keyword kw">when</span> <span class="ruby-value">90</span><span class="ruby-operator">..</span><span class="ruby-value">1440</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">lwr</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_hour_about</span>, (<span class="ruby-identifier">distance_in_minutes</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-value">60.0</span>).<span class="ruby-identifier">round</span>)
|
|
||||||
37: <span class="ruby-keyword kw">when</span> <span class="ruby-value">1441</span><span class="ruby-operator">..</span><span class="ruby-value">2880</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">lwr</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_day</span>, <span class="ruby-value">1</span>)
|
|
||||||
38: <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">lwr</span>(<span class="ruby-identifier">:actionview_datehelper_time_in_words_day</span>, (<span class="ruby-identifier">distance_in_minutes</span> <span class="ruby-operator">/</span> <span class="ruby-value">1440</span>).<span class="ruby-identifier">round</span>)
|
|
||||||
39: <span class="ruby-keyword kw">end</span>
|
|
||||||
40: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000042" class="method-detail">
|
|
||||||
<a name="M000042"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000042" class="method-signature">
|
|
||||||
<span class="method-name">select_day</span><span class="method-args">(date, options = {})</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
This method has been modified so that a localized string can be appended to
|
|
||||||
the day numbers.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000042-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-rails-text.rb, line 43</span>
|
|
||||||
43: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">select_day</span>(<span class="ruby-identifier">date</span>, <span class="ruby-identifier">options</span> = {})
|
|
||||||
44: <span class="ruby-identifier">day_options</span> = []
|
|
||||||
45: <span class="ruby-identifier">prefix</span> = <span class="ruby-identifier">l</span> <span class="ruby-identifier">:actionview_datehelper_select_day_prefix</span>
|
|
||||||
46:
|
|
||||||
47: <span class="ruby-value">1</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-value">31</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">day</span><span class="ruby-operator">|</span>
|
|
||||||
48: <span class="ruby-identifier">day_options</span> <span class="ruby-operator"><<</span> ((<span class="ruby-identifier">date</span> <span class="ruby-operator">&&</span> (<span class="ruby-identifier">date</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Fixnum</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">date</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">date</span>.<span class="ruby-identifier">day</span>) <span class="ruby-operator">==</span> <span class="ruby-identifier">day</span>) <span class="ruby-operator">?</span>
|
|
||||||
49: <span class="ruby-node">%(<option value="#{day}" selected="selected">#{day}#{prefix}</option>\n)</span> <span class="ruby-operator">:</span>
|
|
||||||
50: <span class="ruby-node">%(<option value="#{day}">#{day}#{prefix}</option>\n)</span>
|
|
||||||
51: )
|
|
||||||
52: <span class="ruby-keyword kw">end</span>
|
|
||||||
53:
|
|
||||||
54: <span class="ruby-identifier">select_html</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:field_name</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'day'</span>, <span class="ruby-identifier">day_options</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:prefix</span>], <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:include_blank</span>], <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:discard_type</span>], <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:disabled</span>])
|
|
||||||
55: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000043" class="method-detail">
|
|
||||||
<a name="M000043"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000043" class="method-signature">
|
|
||||||
<span class="method-name">select_month</span><span class="method-args">(date, options = {})</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
This method has been modified so that
|
|
||||||
</p>
|
|
||||||
<ul>
|
|
||||||
<li>the month names are localized.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>it uses options: <tt>:min_date</tt>, <tt>:max_date</tt>,
|
|
||||||
<tt>:start_month</tt>, <tt>:end_month</tt>
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>a localized string can be appended to the month numbers when the
|
|
||||||
<tt>:use_month_numbers</tt> option is specified.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000043-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-rails-text.rb, line 61</span>
|
|
||||||
61: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">select_month</span>(<span class="ruby-identifier">date</span>, <span class="ruby-identifier">options</span> = {})
|
|
||||||
62: <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">LOCALIZED_MONTHNAMES</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">current_language</span>)
|
|
||||||
63: <span class="ruby-constant">LOCALIZED_MONTHNAMES</span>[<span class="ruby-identifier">current_language</span>] = [<span class="ruby-value str">''</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">l</span>(<span class="ruby-identifier">:actionview_datehelper_select_month_names</span>).<span class="ruby-identifier">split</span>(<span class="ruby-value str">','</span>)
|
|
||||||
64: <span class="ruby-constant">LOCALIZED_ABBR_MONTHNAMES</span>[<span class="ruby-identifier">current_language</span>] = [<span class="ruby-value str">''</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">l</span>(<span class="ruby-identifier">:actionview_datehelper_select_month_names_abbr</span>).<span class="ruby-identifier">split</span>(<span class="ruby-value str">','</span>)
|
|
||||||
65: <span class="ruby-keyword kw">end</span>
|
|
||||||
66:
|
|
||||||
67: <span class="ruby-identifier">month_options</span> = []
|
|
||||||
68: <span class="ruby-identifier">month_names</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_short_month</span>] <span class="ruby-operator">?</span> <span class="ruby-constant">LOCALIZED_ABBR_MONTHNAMES</span>[<span class="ruby-identifier">current_language</span>] <span class="ruby-operator">:</span> <span class="ruby-constant">LOCALIZED_MONTHNAMES</span>[<span class="ruby-identifier">current_language</span>]
|
|
||||||
69:
|
|
||||||
70: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:min_date</span>) <span class="ruby-operator">&&</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:max_date</span>)
|
|
||||||
71: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:min_date</span>].<span class="ruby-identifier">year</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:max_date</span>].<span class="ruby-identifier">year</span>
|
|
||||||
72: <span class="ruby-identifier">start_month</span>, <span class="ruby-identifier">end_month</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:min_date</span>].<span class="ruby-identifier">month</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:max_date</span>].<span class="ruby-identifier">month</span>
|
|
||||||
73: <span class="ruby-keyword kw">end</span>
|
|
||||||
74: <span class="ruby-keyword kw">end</span>
|
|
||||||
75: <span class="ruby-identifier">start_month</span> = (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:start_month</span>] <span class="ruby-operator">||</span> <span class="ruby-value">1</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">start_month</span>
|
|
||||||
76: <span class="ruby-identifier">end_month</span> = (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:end_month</span>] <span class="ruby-operator">||</span> <span class="ruby-value">12</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">end_month</span>
|
|
||||||
77: <span class="ruby-identifier">prefix</span> = <span class="ruby-identifier">l</span> <span class="ruby-identifier">:actionview_datehelper_select_month_prefix</span>
|
|
||||||
78:
|
|
||||||
79: <span class="ruby-identifier">start_month</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">end_month</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">month_number</span><span class="ruby-operator">|</span>
|
|
||||||
80: <span class="ruby-identifier">month_name</span> = <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_month_numbers</span>]
|
|
||||||
81: <span class="ruby-node">"#{month_number}#{prefix}"</span>
|
|
||||||
82: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:add_month_numbers</span>]
|
|
||||||
83: <span class="ruby-identifier">month_number</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">' - '</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">month_names</span>[<span class="ruby-identifier">month_number</span>]
|
|
||||||
84: <span class="ruby-keyword kw">else</span>
|
|
||||||
85: <span class="ruby-identifier">month_names</span>[<span class="ruby-identifier">month_number</span>]
|
|
||||||
86: <span class="ruby-keyword kw">end</span>
|
|
||||||
87:
|
|
||||||
88: <span class="ruby-identifier">month_options</span> <span class="ruby-operator"><<</span> ((<span class="ruby-identifier">date</span> <span class="ruby-operator">&&</span> (<span class="ruby-identifier">date</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Fixnum</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">date</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">date</span>.<span class="ruby-identifier">month</span>) <span class="ruby-operator">==</span> <span class="ruby-identifier">month_number</span>) <span class="ruby-operator">?</span>
|
|
||||||
89: <span class="ruby-node">%(<option value="#{month_number}" selected="selected">#{month_name}</option>\n)</span> <span class="ruby-operator">:</span>
|
|
||||||
90: <span class="ruby-node">%(<option value="#{month_number}">#{month_name}</option>\n)</span>
|
|
||||||
91: )
|
|
||||||
92: <span class="ruby-keyword kw">end</span>
|
|
||||||
93:
|
|
||||||
94: <span class="ruby-identifier">select_html</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:field_name</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'month'</span>, <span class="ruby-identifier">month_options</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:prefix</span>], <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:include_blank</span>], <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:discard_type</span>], <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:disabled</span>])
|
|
||||||
95: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000044" class="method-detail">
|
|
||||||
<a name="M000044"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000044" class="method-signature">
|
|
||||||
<span class="method-name">select_year</span><span class="method-args">(date, options = {})</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
This method has been modified so that
|
|
||||||
</p>
|
|
||||||
<ul>
|
|
||||||
<li>it uses options: <tt>:min_date</tt>, <tt>:max_date</tt>
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>a localized string can be appended to the years numbers.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000044-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-rails-text.rb, line 100</span>
|
|
||||||
100: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">select_year</span>(<span class="ruby-identifier">date</span>, <span class="ruby-identifier">options</span> = {})
|
|
||||||
101: <span class="ruby-identifier">year_options</span> = []
|
|
||||||
102: <span class="ruby-identifier">y</span> = <span class="ruby-identifier">date</span> <span class="ruby-value">? </span>(<span class="ruby-identifier">date</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Fixnum</span>) <span class="ruby-operator">?</span> (<span class="ruby-identifier">y</span> = (<span class="ruby-identifier">date</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>) <span class="ruby-operator">?</span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">today</span>.<span class="ruby-identifier">year</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">date</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">date</span>.<span class="ruby-identifier">year</span>) <span class="ruby-operator">:</span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">today</span>.<span class="ruby-identifier">year</span>
|
|
||||||
103:
|
|
||||||
104: <span class="ruby-identifier">start_year</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:min_date</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:min_date</span>].<span class="ruby-identifier">year</span> <span class="ruby-operator">:</span> (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:start_year</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">y</span><span class="ruby-operator">-</span><span class="ruby-value">5</span>)
|
|
||||||
105: <span class="ruby-identifier">end_year</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:max_date</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:max_date</span>].<span class="ruby-identifier">year</span> <span class="ruby-operator">:</span> (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:end_year</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">y</span><span class="ruby-operator">+</span><span class="ruby-value">5</span>)
|
|
||||||
106: <span class="ruby-identifier">step_val</span> = <span class="ruby-identifier">start_year</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">end_year</span> <span class="ruby-value">? </span><span class="ruby-value">1</span> <span class="ruby-operator">:</span> <span class="ruby-value">-1</span>
|
|
||||||
107: <span class="ruby-identifier">prefix</span> = <span class="ruby-identifier">l</span> <span class="ruby-identifier">:actionview_datehelper_select_year_prefix</span>
|
|
||||||
108:
|
|
||||||
109: <span class="ruby-identifier">start_year</span>.<span class="ruby-identifier">step</span>(<span class="ruby-identifier">end_year</span>, <span class="ruby-identifier">step_val</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">year</span><span class="ruby-operator">|</span>
|
|
||||||
110: <span class="ruby-identifier">year_options</span> <span class="ruby-operator"><<</span> ((<span class="ruby-identifier">date</span> <span class="ruby-operator">&&</span> (<span class="ruby-identifier">date</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Fixnum</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">date</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">date</span>.<span class="ruby-identifier">year</span>) <span class="ruby-operator">==</span> <span class="ruby-identifier">year</span>) <span class="ruby-operator">?</span>
|
|
||||||
111: <span class="ruby-node">%(<option value="#{year}" selected="selected">#{year}#{prefix}</option>\n)</span> <span class="ruby-operator">:</span>
|
|
||||||
112: <span class="ruby-node">%(<option value="#{year}">#{year}#{prefix}</option>\n)</span>
|
|
||||||
113: )
|
|
||||||
114: <span class="ruby-keyword kw">end</span>
|
|
||||||
115:
|
|
||||||
116: <span class="ruby-identifier">select_html</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:field_name</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'year'</span>, <span class="ruby-identifier">year_options</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:prefix</span>], <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:include_blank</span>], <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:discard_type</span>], <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:disabled</span>])
|
|
||||||
117: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
-167
@@ -1,167 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Class: ActionView::Helpers::InstanceTag</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="classHeader">
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Class</strong></td>
|
|
||||||
<td class="class-name-in-header">ActionView::Helpers::InstanceTag</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>In:</strong></td>
|
|
||||||
<td>
|
|
||||||
<a href="../../../files/lib/gloc-rails-text_rb.html">
|
|
||||||
lib/gloc-rails-text.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
<a href="../../../files/lib/gloc-rails_rb.html">
|
|
||||||
lib/gloc-rails.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Parent:</strong></td>
|
|
||||||
<td>
|
|
||||||
Object
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
The private method <tt>add_options</tt> is overridden so that "Please
|
|
||||||
select" is localized.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-list">
|
|
||||||
<h3 class="section-bar">Methods</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<a href="#M000045">current_language</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
<div id="includes">
|
|
||||||
<h3 class="section-bar">Included Modules</h3>
|
|
||||||
|
|
||||||
<div id="includes-list">
|
|
||||||
<span class="include-name"><a href="../../GLoc.html">GLoc</a></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
<div id="methods">
|
|
||||||
<h3 class="section-bar">Public Instance methods</h3>
|
|
||||||
|
|
||||||
<div id="method-M000045" class="method-detail">
|
|
||||||
<a name="M000045"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000045" class="method-signature">
|
|
||||||
<span class="method-name">current_language</span><span class="method-args">()</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Inherits the current language from the template object.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000045-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-rails.rb, line 119</span>
|
|
||||||
119: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">current_language</span>
|
|
||||||
120: <span class="ruby-ivar">@template_object</span>.<span class="ruby-identifier">current_language</span>
|
|
||||||
121: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,215 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Class: ActiveRecord::Errors</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="classHeader">
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Class</strong></td>
|
|
||||||
<td class="class-name-in-header">ActiveRecord::Errors</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>In:</strong></td>
|
|
||||||
<td>
|
|
||||||
<a href="../../files/lib/gloc-rails_rb.html">
|
|
||||||
lib/gloc-rails.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Parent:</strong></td>
|
|
||||||
<td>
|
|
||||||
Object
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-list">
|
|
||||||
<h3 class="section-bar">Methods</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<a href="#M000039">add</a>
|
|
||||||
<a href="#M000040">current_language</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
<div id="includes">
|
|
||||||
<h3 class="section-bar">Included Modules</h3>
|
|
||||||
|
|
||||||
<div id="includes-list">
|
|
||||||
<span class="include-name"><a href="../GLoc.html">GLoc</a></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="aliases-list">
|
|
||||||
<h3 class="section-bar">External Aliases</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<table summary="aliases">
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">add</td>
|
|
||||||
<td>-></td>
|
|
||||||
<td class="context-item-value">add_without_gloc</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
<div id="methods">
|
|
||||||
<h3 class="section-bar">Public Instance methods</h3>
|
|
||||||
|
|
||||||
<div id="method-M000039" class="method-detail">
|
|
||||||
<a name="M000039"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000039" class="method-signature">
|
|
||||||
<span class="method-name">add</span><span class="method-args">(attribute, msg= @@default_error_messages[:invalid])</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
The <a href="../GLoc.html">GLoc</a> version of this method provides two
|
|
||||||
extra features
|
|
||||||
</p>
|
|
||||||
<ul>
|
|
||||||
<li>If <tt>msg</tt> is a string, it will be considered a <a
|
|
||||||
href="../GLoc.html">GLoc</a> string key.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>If <tt>msg</tt> is an array, the first element will be considered the
|
|
||||||
string and the remaining elements will be considered arguments for the
|
|
||||||
string. Eg. <tt>[‘Hi %s.’,’John’]</tt>
|
|
||||||
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000039-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-rails.rb, line 141</span>
|
|
||||||
141: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">msg</span>= <span class="ruby-ivar">@@default_error_messages</span>[<span class="ruby-identifier">:invalid</span>])
|
|
||||||
142: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
|
|
||||||
143: <span class="ruby-identifier">args</span>= <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">clone</span>
|
|
||||||
144: <span class="ruby-identifier">msg</span>= <span class="ruby-identifier">args</span>.<span class="ruby-identifier">shift</span>
|
|
||||||
145: <span class="ruby-identifier">args</span>= <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span>
|
|
||||||
146: <span class="ruby-keyword kw">end</span>
|
|
||||||
147: <span class="ruby-identifier">msg</span>= <span class="ruby-identifier">ltry</span>(<span class="ruby-identifier">msg</span>)
|
|
||||||
148: <span class="ruby-identifier">msg</span>= <span class="ruby-identifier">msg</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">args</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
|
|
||||||
149: <span class="ruby-identifier">add_without_gloc</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">msg</span>)
|
|
||||||
150: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000040" class="method-detail">
|
|
||||||
<a name="M000040"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000040" class="method-signature">
|
|
||||||
<span class="method-name">current_language</span><span class="method-args">()</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Inherits the current language from the base record.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000040-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-rails.rb, line 152</span>
|
|
||||||
152: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">current_language</span>
|
|
||||||
153: <span class="ruby-ivar">@base</span>.<span class="ruby-identifier">current_language</span>
|
|
||||||
154: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Vendored
-217
@@ -1,217 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Module: ActiveRecord::Validations::ClassMethods</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="classHeader">
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Module</strong></td>
|
|
||||||
<td class="class-name-in-header">ActiveRecord::Validations::ClassMethods</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>In:</strong></td>
|
|
||||||
<td>
|
|
||||||
<a href="../../../files/lib/gloc-rails_rb.html">
|
|
||||||
lib/gloc-rails.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-list">
|
|
||||||
<h3 class="section-bar">Methods</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<a href="#M000037">validates_length_of</a>
|
|
||||||
<a href="#M000038">validates_size_of</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
<div id="methods">
|
|
||||||
<h3 class="section-bar">Public Instance methods</h3>
|
|
||||||
|
|
||||||
<div id="method-M000037" class="method-detail">
|
|
||||||
<a name="M000037"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000037" class="method-signature">
|
|
||||||
<span class="method-name">validates_length_of</span><span class="method-args">(*attrs)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
The default Rails version of this function creates an error message and
|
|
||||||
then passes it to <a href="../Errors.html">ActiveRecord.Errors</a>. The <a
|
|
||||||
href="../../GLoc.html">GLoc</a> version of this method, sends an array to
|
|
||||||
<a href="../Errors.html">ActiveRecord.Errors</a> that will be turned into a
|
|
||||||
string by <a href="../Errors.html">ActiveRecord.Errors</a> which in turn
|
|
||||||
allows for the message of this validation function to be a <a
|
|
||||||
href="../../GLoc.html">GLoc</a> string key.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000037-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-rails.rb, line 164</span>
|
|
||||||
164: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">validates_length_of</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">attrs</span>)
|
|
||||||
165: <span class="ruby-comment cmt"># Merge given options with defaults.</span>
|
|
||||||
166: <span class="ruby-identifier">options</span> = {
|
|
||||||
167: <span class="ruby-identifier">:too_long</span> =<span class="ruby-operator">></span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Errors</span>.<span class="ruby-identifier">default_error_messages</span>[<span class="ruby-identifier">:too_long</span>],
|
|
||||||
168: <span class="ruby-identifier">:too_short</span> =<span class="ruby-operator">></span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Errors</span>.<span class="ruby-identifier">default_error_messages</span>[<span class="ruby-identifier">:too_short</span>],
|
|
||||||
169: <span class="ruby-identifier">:wrong_length</span> =<span class="ruby-operator">></span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Errors</span>.<span class="ruby-identifier">default_error_messages</span>[<span class="ruby-identifier">:wrong_length</span>]
|
|
||||||
170: }.<span class="ruby-identifier">merge</span>(<span class="ruby-constant">DEFAULT_VALIDATION_OPTIONS</span>)
|
|
||||||
171: <span class="ruby-identifier">options</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">pop</span>.<span class="ruby-identifier">symbolize_keys</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
|
|
||||||
172:
|
|
||||||
173: <span class="ruby-comment cmt"># Ensure that one and only one range option is specified.</span>
|
|
||||||
174: <span class="ruby-identifier">range_options</span> = <span class="ruby-constant">ALL_RANGE_OPTIONS</span> <span class="ruby-operator">&</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">keys</span>
|
|
||||||
175: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">range_options</span>.<span class="ruby-identifier">size</span>
|
|
||||||
176: <span class="ruby-keyword kw">when</span> <span class="ruby-value">0</span>
|
|
||||||
177: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'Range unspecified. Specify the :within, :maximum, :minimum, or :is option.'</span>
|
|
||||||
178: <span class="ruby-keyword kw">when</span> <span class="ruby-value">1</span>
|
|
||||||
179: <span class="ruby-comment cmt"># Valid number of options; do nothing.</span>
|
|
||||||
180: <span class="ruby-keyword kw">else</span>
|
|
||||||
181: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'Too many range options specified. Choose only one.'</span>
|
|
||||||
182: <span class="ruby-keyword kw">end</span>
|
|
||||||
183:
|
|
||||||
184: <span class="ruby-comment cmt"># Get range option and value.</span>
|
|
||||||
185: <span class="ruby-identifier">option</span> = <span class="ruby-identifier">range_options</span>.<span class="ruby-identifier">first</span>
|
|
||||||
186: <span class="ruby-identifier">option_value</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">range_options</span>.<span class="ruby-identifier">first</span>]
|
|
||||||
187:
|
|
||||||
188: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">option</span>
|
|
||||||
189: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:within</span>, <span class="ruby-identifier">:in</span>
|
|
||||||
190: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">":#{option} must be a Range"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">option_value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Range</span>)
|
|
||||||
191:
|
|
||||||
192: <span class="ruby-identifier">too_short</span> = [<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:too_short</span>] , <span class="ruby-identifier">option_value</span>.<span class="ruby-identifier">begin</span>]
|
|
||||||
193: <span class="ruby-identifier">too_long</span> = [<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:too_long</span>] , <span class="ruby-identifier">option_value</span>.<span class="ruby-identifier">end</span> ]
|
|
||||||
194:
|
|
||||||
195: <span class="ruby-identifier">validates_each</span>(<span class="ruby-identifier">attrs</span>, <span class="ruby-identifier">options</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">record</span>, <span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
|
|
||||||
196: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">//</span>).<span class="ruby-identifier">size</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">option_value</span>.<span class="ruby-identifier">begin</span>
|
|
||||||
197: <span class="ruby-identifier">record</span>.<span class="ruby-identifier">errors</span>.<span class="ruby-identifier">add</span>(<span class="ruby-identifier">attr</span>, <span class="ruby-identifier">too_short</span>)
|
|
||||||
198: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">//</span>).<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-identifier">option_value</span>.<span class="ruby-identifier">end</span>
|
|
||||||
199: <span class="ruby-identifier">record</span>.<span class="ruby-identifier">errors</span>.<span class="ruby-identifier">add</span>(<span class="ruby-identifier">attr</span>, <span class="ruby-identifier">too_long</span>)
|
|
||||||
200: <span class="ruby-keyword kw">end</span>
|
|
||||||
201: <span class="ruby-keyword kw">end</span>
|
|
||||||
202: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:is</span>, <span class="ruby-identifier">:minimum</span>, <span class="ruby-identifier">:maximum</span>
|
|
||||||
203: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">":#{option} must be a nonnegative Integer"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">option_value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">option_value</span> <span class="ruby-operator">>=</span> <span class="ruby-value">0</span>
|
|
||||||
204:
|
|
||||||
205: <span class="ruby-comment cmt"># Declare different validations per option.</span>
|
|
||||||
206: <span class="ruby-identifier">validity_checks</span> = { <span class="ruby-identifier">:is</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"=="</span>, <span class="ruby-identifier">:minimum</span> =<span class="ruby-operator">></span> <span class="ruby-value str">">="</span>, <span class="ruby-identifier">:maximum</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"<="</span> }
|
|
||||||
207: <span class="ruby-identifier">message_options</span> = { <span class="ruby-identifier">:is</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:wrong_length</span>, <span class="ruby-identifier">:minimum</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:too_short</span>, <span class="ruby-identifier">:maximum</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:too_long</span> }
|
|
||||||
208:
|
|
||||||
209: <span class="ruby-identifier">message</span> = [(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:message</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">message_options</span>[<span class="ruby-identifier">option</span>]]) , <span class="ruby-identifier">option_value</span>]
|
|
||||||
210:
|
|
||||||
211: <span class="ruby-identifier">validates_each</span>(<span class="ruby-identifier">attrs</span>, <span class="ruby-identifier">options</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">record</span>, <span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
|
|
||||||
212: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">String</span>)
|
|
||||||
213: <span class="ruby-identifier">record</span>.<span class="ruby-identifier">errors</span>.<span class="ruby-identifier">add</span>(<span class="ruby-identifier">attr</span>, <span class="ruby-identifier">message</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-operator">!</span><span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">//</span>).<span class="ruby-identifier">size</span>.<span class="ruby-identifier">method</span>(<span class="ruby-identifier">validity_checks</span>[<span class="ruby-identifier">option</span>])[<span class="ruby-identifier">option_value</span>]
|
|
||||||
214: <span class="ruby-keyword kw">else</span>
|
|
||||||
215: <span class="ruby-identifier">record</span>.<span class="ruby-identifier">errors</span>.<span class="ruby-identifier">add</span>(<span class="ruby-identifier">attr</span>, <span class="ruby-identifier">message</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-operator">!</span><span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">size</span>.<span class="ruby-identifier">method</span>(<span class="ruby-identifier">validity_checks</span>[<span class="ruby-identifier">option</span>])[<span class="ruby-identifier">option_value</span>]
|
|
||||||
216: <span class="ruby-keyword kw">end</span>
|
|
||||||
217: <span class="ruby-keyword kw">end</span>
|
|
||||||
218: <span class="ruby-keyword kw">end</span>
|
|
||||||
219: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000038" class="method-detail">
|
|
||||||
<a name="M000038"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<span class="method-name">validates_size_of</span><span class="method-args">(*attrs)</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Alias for <a href="ClassMethods.html#M000037">validates_length_of</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,774 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Module: GLoc</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="classHeader">
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Module</strong></td>
|
|
||||||
<td class="class-name-in-header">GLoc</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>In:</strong></td>
|
|
||||||
<td>
|
|
||||||
<a href="../files/lib/gloc-helpers_rb.html">
|
|
||||||
lib/gloc-helpers.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
<a href="../files/lib/gloc-internal_rb.html">
|
|
||||||
lib/gloc-internal.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
<a href="../files/lib/gloc-version_rb.html">
|
|
||||||
lib/gloc-version.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
<a href="../files/lib/gloc_rb.html">
|
|
||||||
lib/gloc.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
Copyright © 2005-2006 David Barri
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-list">
|
|
||||||
<h3 class="section-bar">Methods</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<a href="#M000004">add_localized_strings</a>
|
|
||||||
<a href="#M000005">backup_state</a>
|
|
||||||
<a href="#M000006">clear_strings</a>
|
|
||||||
<a href="#M000007">clear_strings_except</a>
|
|
||||||
<a href="#M000002">current_language</a>
|
|
||||||
<a href="#M000003">current_language</a>
|
|
||||||
<a href="#M000008">get_charset</a>
|
|
||||||
<a href="#M000009">get_config</a>
|
|
||||||
<a href="#M000010">load_gloc_default_localized_strings</a>
|
|
||||||
<a href="#M000011">load_localized_strings</a>
|
|
||||||
<a href="#M000012">restore_state</a>
|
|
||||||
<a href="#M000013">set_charset</a>
|
|
||||||
<a href="#M000014">set_config</a>
|
|
||||||
<a href="#M000015">set_kcode</a>
|
|
||||||
<a href="#M000016">similar_language</a>
|
|
||||||
<a href="#M000018">valid_language?</a>
|
|
||||||
<a href="#M000017">valid_languages</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
<div id="includes">
|
|
||||||
<h3 class="section-bar">Included Modules</h3>
|
|
||||||
|
|
||||||
<div id="includes-list">
|
|
||||||
<span class="include-name"><a href="GLoc/InstanceMethods.html">::GLoc::InstanceMethods</a></span>
|
|
||||||
<span class="include-name"><a href="GLoc/InstanceMethods.html">::GLoc::InstanceMethods</a></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
<div id="class-list">
|
|
||||||
<h3 class="section-bar">Classes and Modules</h3>
|
|
||||||
|
|
||||||
Module <a href="GLoc/ClassMethods.html" class="link">GLoc::ClassMethods</a><br />
|
|
||||||
Module <a href="GLoc/Helpers.html" class="link">GLoc::Helpers</a><br />
|
|
||||||
Module <a href="GLoc/InstanceMethods.html" class="link">GLoc::InstanceMethods</a><br />
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="constants-list">
|
|
||||||
<h3 class="section-bar">Constants</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<table summary="Constants">
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">LOCALIZED_STRINGS</td>
|
|
||||||
<td>=</td>
|
|
||||||
<td class="context-item-value">{}</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">RULES</td>
|
|
||||||
<td>=</td>
|
|
||||||
<td class="context-item-value">{}</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">LOWERCASE_LANGUAGES</td>
|
|
||||||
<td>=</td>
|
|
||||||
<td class="context-item-value">{}</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">UTF_8</td>
|
|
||||||
<td>=</td>
|
|
||||||
<td class="context-item-value">'utf-8'</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">SHIFT_JIS</td>
|
|
||||||
<td>=</td>
|
|
||||||
<td class="context-item-value">'sjis'</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">EUC_JP</td>
|
|
||||||
<td>=</td>
|
|
||||||
<td class="context-item-value">'euc-jp'</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="aliases-list">
|
|
||||||
<h3 class="section-bar">External Aliases</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<table summary="aliases">
|
|
||||||
<tr class="top-aligned-row context-row">
|
|
||||||
<td class="context-item-name">clear_strings</td>
|
|
||||||
<td>-></td>
|
|
||||||
<td class="context-item-value">_clear_strings</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
<div id="methods">
|
|
||||||
<h3 class="section-bar">Public Class methods</h3>
|
|
||||||
|
|
||||||
<div id="method-M000004" class="method-detail">
|
|
||||||
<a name="M000004"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000004" class="method-signature">
|
|
||||||
<span class="method-name">add_localized_strings</span><span class="method-args">(lang, symbol_hash, override=true, strings_charset=nil)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Adds a collection of localized strings to the in-memory string store.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000004-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 113</span>
|
|
||||||
113: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_localized_strings</span>(<span class="ruby-identifier">lang</span>, <span class="ruby-identifier">symbol_hash</span>, <span class="ruby-identifier">override</span>=<span class="ruby-keyword kw">true</span>, <span class="ruby-identifier">strings_charset</span>=<span class="ruby-keyword kw">nil</span>)
|
|
||||||
114: <span class="ruby-identifier">_verbose_msg</span> {<span class="ruby-node">"Adding #{symbol_hash.size} #{lang} strings."</span>}
|
|
||||||
115: <span class="ruby-identifier">_add_localized_strings</span>(<span class="ruby-identifier">lang</span>, <span class="ruby-identifier">symbol_hash</span>, <span class="ruby-identifier">override</span>, <span class="ruby-identifier">strings_charset</span>)
|
|
||||||
116: <span class="ruby-identifier">_verbose_msg</span> <span class="ruby-identifier">:stats</span>
|
|
||||||
117: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000005" class="method-detail">
|
|
||||||
<a name="M000005"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000005" class="method-signature">
|
|
||||||
<span class="method-name">backup_state</span><span class="method-args">(clear=false)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Creates a backup of the internal state of <a href="GLoc.html">GLoc</a> (ie.
|
|
||||||
strings, langs, rules, config) and optionally clears everything.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000005-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 121</span>
|
|
||||||
121: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">backup_state</span>(<span class="ruby-identifier">clear</span>=<span class="ruby-keyword kw">false</span>)
|
|
||||||
122: <span class="ruby-identifier">s</span>= <span class="ruby-identifier">_get_internal_state_vars</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">clone</span>}
|
|
||||||
123: <span class="ruby-identifier">_get_internal_state_vars</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">clear</span>} <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">clear</span>
|
|
||||||
124: <span class="ruby-identifier">s</span>
|
|
||||||
125: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000006" class="method-detail">
|
|
||||||
<a name="M000006"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000006" class="method-signature">
|
|
||||||
<span class="method-name">clear_strings</span><span class="method-args">(*languages)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Removes all localized strings from memory, either of a certain language (or
|
|
||||||
languages), or entirely.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000006-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 129</span>
|
|
||||||
129: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_strings</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">languages</span>)
|
|
||||||
130: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">languages</span>.<span class="ruby-identifier">empty?</span>
|
|
||||||
131: <span class="ruby-identifier">_verbose_msg</span> {<span class="ruby-value str">"Clearing all strings"</span>}
|
|
||||||
132: <span class="ruby-constant">LOCALIZED_STRINGS</span>.<span class="ruby-identifier">clear</span>
|
|
||||||
133: <span class="ruby-constant">LOWERCASE_LANGUAGES</span>.<span class="ruby-identifier">clear</span>
|
|
||||||
134: <span class="ruby-keyword kw">else</span>
|
|
||||||
135: <span class="ruby-identifier">languages</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span>
|
|
||||||
136: <span class="ruby-identifier">_verbose_msg</span> {<span class="ruby-node">"Clearing :#{l} strings"</span>}
|
|
||||||
137: <span class="ruby-identifier">l</span>= <span class="ruby-identifier">l</span>.<span class="ruby-identifier">to_sym</span>
|
|
||||||
138: <span class="ruby-constant">LOCALIZED_STRINGS</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">l</span>
|
|
||||||
139: <span class="ruby-constant">LOWERCASE_LANGUAGES</span>.<span class="ruby-identifier">each_pair</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-constant">LOWERCASE_LANGUAGES</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">k</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">v</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">l</span>}
|
|
||||||
140: }
|
|
||||||
141: <span class="ruby-keyword kw">end</span>
|
|
||||||
142: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000007" class="method-detail">
|
|
||||||
<a name="M000007"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000007" class="method-signature">
|
|
||||||
<span class="method-name">clear_strings_except</span><span class="method-args">(*languages)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Removes all localized strings from memory, except for those of certain
|
|
||||||
specified languages.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000007-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 146</span>
|
|
||||||
146: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_strings_except</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">languages</span>)
|
|
||||||
147: <span class="ruby-identifier">clear</span>= (<span class="ruby-constant">LOCALIZED_STRINGS</span>.<span class="ruby-identifier">keys</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">languages</span>)
|
|
||||||
148: <span class="ruby-identifier">_clear_strings</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">clear</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">clear</span>.<span class="ruby-identifier">empty?</span>
|
|
||||||
149: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000003" class="method-detail">
|
|
||||||
<a name="M000003"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000003" class="method-signature">
|
|
||||||
<span class="method-name">current_language</span><span class="method-args">()</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Returns the default language
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000003-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 108</span>
|
|
||||||
108: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">current_language</span>
|
|
||||||
109: <span class="ruby-constant">GLoc</span><span class="ruby-operator">::</span><span class="ruby-constant">CONFIG</span>[<span class="ruby-identifier">:default_language</span>]
|
|
||||||
110: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000008" class="method-detail">
|
|
||||||
<a name="M000008"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000008" class="method-signature">
|
|
||||||
<span class="method-name">get_charset</span><span class="method-args">(lang)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Returns the charset used to store localized strings in memory.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000008-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 152</span>
|
|
||||||
152: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_charset</span>(<span class="ruby-identifier">lang</span>)
|
|
||||||
153: <span class="ruby-constant">CONFIG</span>[<span class="ruby-identifier">:internal_charset_per_lang</span>][<span class="ruby-identifier">lang</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">CONFIG</span>[<span class="ruby-identifier">:internal_charset</span>]
|
|
||||||
154: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000009" class="method-detail">
|
|
||||||
<a name="M000009"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000009" class="method-signature">
|
|
||||||
<span class="method-name">get_config</span><span class="method-args">(key)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Returns a <a href="GLoc.html">GLoc</a> configuration value.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000009-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 157</span>
|
|
||||||
157: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_config</span>(<span class="ruby-identifier">key</span>)
|
|
||||||
158: <span class="ruby-constant">CONFIG</span>[<span class="ruby-identifier">key</span>]
|
|
||||||
159: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000010" class="method-detail">
|
|
||||||
<a name="M000010"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000010" class="method-signature">
|
|
||||||
<span class="method-name">load_gloc_default_localized_strings</span><span class="method-args">(override=false)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Loads the localized strings that are included in the <a
|
|
||||||
href="GLoc.html">GLoc</a> library.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000010-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 162</span>
|
|
||||||
162: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_gloc_default_localized_strings</span>(<span class="ruby-identifier">override</span>=<span class="ruby-keyword kw">false</span>)
|
|
||||||
163: <span class="ruby-constant">GLoc</span>.<span class="ruby-identifier">load_localized_strings</span> <span class="ruby-node">"#{File.dirname(__FILE__)}/../lang"</span>, <span class="ruby-identifier">override</span>
|
|
||||||
164: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000011" class="method-detail">
|
|
||||||
<a name="M000011"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000011" class="method-signature">
|
|
||||||
<span class="method-name">load_localized_strings</span><span class="method-args">(dir=nil, override=true)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Loads localized strings from all yml files in the specifed directory.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000011-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 167</span>
|
|
||||||
167: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_localized_strings</span>(<span class="ruby-identifier">dir</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">override</span>=<span class="ruby-keyword kw">true</span>)
|
|
||||||
168: <span class="ruby-identifier">_charset_required</span>
|
|
||||||
169: <span class="ruby-identifier">_get_lang_file_list</span>(<span class="ruby-identifier">dir</span>).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">filename</span><span class="ruby-operator">|</span>
|
|
||||||
170:
|
|
||||||
171: <span class="ruby-comment cmt"># Load file</span>
|
|
||||||
172: <span class="ruby-identifier">raw_hash</span> = <span class="ruby-constant">YAML</span><span class="ruby-operator">::</span><span class="ruby-identifier">load</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">filename</span>))
|
|
||||||
173: <span class="ruby-identifier">raw_hash</span>={} <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">raw_hash</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Hash</span>)
|
|
||||||
174: <span class="ruby-identifier">filename</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/([^\/\\]+)\.ya?ml$/</span>
|
|
||||||
175: <span class="ruby-identifier">lang</span> = <span class="ruby-identifier">$1</span>.<span class="ruby-identifier">to_sym</span>
|
|
||||||
176: <span class="ruby-identifier">file_charset</span> = <span class="ruby-identifier">raw_hash</span>[<span class="ruby-value str">'file_charset'</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">UTF_8</span>
|
|
||||||
177:
|
|
||||||
178: <span class="ruby-comment cmt"># Convert string keys to symbols</span>
|
|
||||||
179: <span class="ruby-identifier">dest_charset</span>= <span class="ruby-identifier">get_charset</span>(<span class="ruby-identifier">lang</span>)
|
|
||||||
180: <span class="ruby-identifier">_verbose_msg</span> {<span class="ruby-node">"Reading file #{filename} [charset: #{file_charset} --> #{dest_charset}]"</span>}
|
|
||||||
181: <span class="ruby-identifier">symbol_hash</span> = {}
|
|
||||||
182: <span class="ruby-constant">Iconv</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">dest_charset</span>, <span class="ruby-identifier">file_charset</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
|
||||||
183: <span class="ruby-identifier">raw_hash</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
|
|
||||||
184: <span class="ruby-identifier">symbol_hash</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">i</span>.<span class="ruby-identifier">iconv</span>(<span class="ruby-identifier">value</span>)
|
|
||||||
185: }
|
|
||||||
186: <span class="ruby-keyword kw">end</span>
|
|
||||||
187:
|
|
||||||
188: <span class="ruby-comment cmt"># Add strings to repos</span>
|
|
||||||
189: <span class="ruby-identifier">_add_localized_strings</span>(<span class="ruby-identifier">lang</span>, <span class="ruby-identifier">symbol_hash</span>, <span class="ruby-identifier">override</span>)
|
|
||||||
190: }
|
|
||||||
191: <span class="ruby-identifier">_verbose_msg</span> <span class="ruby-identifier">:stats</span>
|
|
||||||
192: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000012" class="method-detail">
|
|
||||||
<a name="M000012"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000012" class="method-signature">
|
|
||||||
<span class="method-name">restore_state</span><span class="method-args">(state)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Restores a backup of <a href="GLoc.html">GLoc</a>’s internal state
|
|
||||||
that was made with <a href="GLoc.html#M000005">backup_state</a>.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000012-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 195</span>
|
|
||||||
195: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restore_state</span>(<span class="ruby-identifier">state</span>)
|
|
||||||
196: <span class="ruby-identifier">_get_internal_state_vars</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
|
|
||||||
197: <span class="ruby-identifier">o</span>.<span class="ruby-identifier">clear</span>
|
|
||||||
198: <span class="ruby-identifier">o</span>.<span class="ruby-identifier">send</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:merge!</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">:merge!</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:concat</span>, <span class="ruby-identifier">state</span>.<span class="ruby-identifier">shift</span>
|
|
||||||
199: <span class="ruby-keyword kw">end</span>
|
|
||||||
200: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000013" class="method-detail">
|
|
||||||
<a name="M000013"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000013" class="method-signature">
|
|
||||||
<span class="method-name">set_charset</span><span class="method-args">(new_charset, *langs)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Sets the charset used to internally store localized strings. You can set
|
|
||||||
the charset to use for a specific language or languages, or if none are
|
|
||||||
specified the charset for ALL localized strings will be set.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000013-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 205</span>
|
|
||||||
205: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_charset</span>(<span class="ruby-identifier">new_charset</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">langs</span>)
|
|
||||||
206: <span class="ruby-constant">CONFIG</span>[<span class="ruby-identifier">:internal_charset_per_lang</span>] <span class="ruby-operator">||=</span> {}
|
|
||||||
207:
|
|
||||||
208: <span class="ruby-comment cmt"># Convert symbol shortcuts</span>
|
|
||||||
209: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_charset</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>)
|
|
||||||
210: <span class="ruby-identifier">new_charset</span>= <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">new_charset</span>
|
|
||||||
211: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:utf8</span>, <span class="ruby-identifier">:utf_8</span> <span class="ruby-keyword kw">then</span> <span class="ruby-constant">UTF_8</span>
|
|
||||||
212: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:sjis</span>, <span class="ruby-identifier">:shift_jis</span>, <span class="ruby-identifier">:shiftjis</span> <span class="ruby-keyword kw">then</span> <span class="ruby-constant">SHIFT_JIS</span>
|
|
||||||
213: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:eucjp</span>, <span class="ruby-identifier">:euc_jp</span> <span class="ruby-keyword kw">then</span> <span class="ruby-constant">EUC_JP</span>
|
|
||||||
214: <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">new_charset</span>.<span class="ruby-identifier">to_s</span>
|
|
||||||
215: <span class="ruby-keyword kw">end</span>
|
|
||||||
216: <span class="ruby-keyword kw">end</span>
|
|
||||||
217:
|
|
||||||
218: <span class="ruby-comment cmt"># Convert existing strings</span>
|
|
||||||
219: (<span class="ruby-identifier">langs</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-value">? </span><span class="ruby-constant">LOCALIZED_STRINGS</span>.<span class="ruby-identifier">keys</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">langs</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">lang</span><span class="ruby-operator">|</span>
|
|
||||||
220: <span class="ruby-identifier">cur_charset</span>= <span class="ruby-identifier">get_charset</span>(<span class="ruby-identifier">lang</span>)
|
|
||||||
221: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cur_charset</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">new_charset</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">cur_charset</span>
|
|
||||||
222: <span class="ruby-identifier">_verbose_msg</span> {<span class="ruby-node">"Converting :#{lang} strings from #{cur_charset} to #{new_charset}"</span>}
|
|
||||||
223: <span class="ruby-constant">Iconv</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">new_charset</span>, <span class="ruby-identifier">cur_charset</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
|
||||||
224: <span class="ruby-identifier">bundle</span>= <span class="ruby-constant">LOCALIZED_STRINGS</span>[<span class="ruby-identifier">lang</span>]
|
|
||||||
225: <span class="ruby-identifier">bundle</span>.<span class="ruby-identifier">each_pair</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">bundle</span>[<span class="ruby-identifier">k</span>]= <span class="ruby-identifier">i</span>.<span class="ruby-identifier">iconv</span>(<span class="ruby-identifier">v</span>)}
|
|
||||||
226: <span class="ruby-keyword kw">end</span>
|
|
||||||
227: <span class="ruby-keyword kw">end</span>
|
|
||||||
228: <span class="ruby-keyword kw">end</span>
|
|
||||||
229:
|
|
||||||
230: <span class="ruby-comment cmt"># Set new charset value</span>
|
|
||||||
231: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">langs</span>.<span class="ruby-identifier">empty?</span>
|
|
||||||
232: <span class="ruby-identifier">_verbose_msg</span> {<span class="ruby-node">"Setting GLoc charset for all languages to #{new_charset}"</span>}
|
|
||||||
233: <span class="ruby-constant">CONFIG</span>[<span class="ruby-identifier">:internal_charset</span>]= <span class="ruby-identifier">new_charset</span>
|
|
||||||
234: <span class="ruby-constant">CONFIG</span>[<span class="ruby-identifier">:internal_charset_per_lang</span>].<span class="ruby-identifier">clear</span>
|
|
||||||
235: <span class="ruby-keyword kw">else</span>
|
|
||||||
236: <span class="ruby-identifier">langs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">lang</span><span class="ruby-operator">|</span>
|
|
||||||
237: <span class="ruby-identifier">_verbose_msg</span> {<span class="ruby-node">"Setting GLoc charset for :#{lang} strings to #{new_charset}"</span>}
|
|
||||||
238: <span class="ruby-constant">CONFIG</span>[<span class="ruby-identifier">:internal_charset_per_lang</span>][<span class="ruby-identifier">lang</span>]= <span class="ruby-identifier">new_charset</span>
|
|
||||||
239: <span class="ruby-keyword kw">end</span>
|
|
||||||
240: <span class="ruby-keyword kw">end</span>
|
|
||||||
241: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000014" class="method-detail">
|
|
||||||
<a name="M000014"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000014" class="method-signature">
|
|
||||||
<span class="method-name">set_config</span><span class="method-args">(hash)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Sets <a href="GLoc.html">GLoc</a> configuration values.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000014-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 244</span>
|
|
||||||
244: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_config</span>(<span class="ruby-identifier">hash</span>)
|
|
||||||
245: <span class="ruby-constant">CONFIG</span>.<span class="ruby-identifier">merge!</span> <span class="ruby-identifier">hash</span>
|
|
||||||
246: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000015" class="method-detail">
|
|
||||||
<a name="M000015"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000015" class="method-signature">
|
|
||||||
<span class="method-name">set_kcode</span><span class="method-args">(charset=nil)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Sets the $KCODE global variable according to a specified charset, or else
|
|
||||||
the current default charset for the default language.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000015-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 250</span>
|
|
||||||
250: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_kcode</span>(<span class="ruby-identifier">charset</span>=<span class="ruby-keyword kw">nil</span>)
|
|
||||||
251: <span class="ruby-identifier">_charset_required</span>
|
|
||||||
252: <span class="ruby-identifier">charset</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">get_charset</span>(<span class="ruby-identifier">current_language</span>)
|
|
||||||
253: <span class="ruby-identifier">$KCODE</span>= <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">charset</span>
|
|
||||||
254: <span class="ruby-keyword kw">when</span> <span class="ruby-constant">UTF_8</span> <span class="ruby-keyword kw">then</span> <span class="ruby-value str">'u'</span>
|
|
||||||
255: <span class="ruby-keyword kw">when</span> <span class="ruby-constant">SHIFT_JIS</span> <span class="ruby-keyword kw">then</span> <span class="ruby-value str">'s'</span>
|
|
||||||
256: <span class="ruby-keyword kw">when</span> <span class="ruby-constant">EUC_JP</span> <span class="ruby-keyword kw">then</span> <span class="ruby-value str">'e'</span>
|
|
||||||
257: <span class="ruby-keyword kw">else</span> <span class="ruby-value str">'n'</span>
|
|
||||||
258: <span class="ruby-keyword kw">end</span>
|
|
||||||
259: <span class="ruby-identifier">_verbose_msg</span> {<span class="ruby-node">"$KCODE set to #{$KCODE}"</span>}
|
|
||||||
260: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000016" class="method-detail">
|
|
||||||
<a name="M000016"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000016" class="method-signature">
|
|
||||||
<span class="method-name">similar_language</span><span class="method-args">(lang)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Tries to find a valid language that is similar to the argument passed. Eg.
|
|
||||||
:en, :en_au, :EN_US are all similar languages. Returns <tt>nil</tt> if no
|
|
||||||
similar languages are found.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000016-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 265</span>
|
|
||||||
265: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">similar_language</span>(<span class="ruby-identifier">lang</span>)
|
|
||||||
266: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">lang</span>.<span class="ruby-identifier">nil?</span>
|
|
||||||
267: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">lang</span>.<span class="ruby-identifier">to_sym</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">valid_language?</span>(<span class="ruby-identifier">lang</span>)
|
|
||||||
268: <span class="ruby-comment cmt"># Check lowercase without dashes</span>
|
|
||||||
269: <span class="ruby-identifier">lang</span>= <span class="ruby-identifier">lang</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'-'</span>,<span class="ruby-value str">'_'</span>)
|
|
||||||
270: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">LOWERCASE_LANGUAGES</span>[<span class="ruby-identifier">lang</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-constant">LOWERCASE_LANGUAGES</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">lang</span>)
|
|
||||||
271: <span class="ruby-comment cmt"># Check without dialect</span>
|
|
||||||
272: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">lang</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^([a-z]+?)[^a-z].*/</span>
|
|
||||||
273: <span class="ruby-identifier">lang</span>= <span class="ruby-identifier">$1</span>
|
|
||||||
274: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">LOWERCASE_LANGUAGES</span>[<span class="ruby-identifier">lang</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-constant">LOWERCASE_LANGUAGES</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">lang</span>)
|
|
||||||
275: <span class="ruby-keyword kw">end</span>
|
|
||||||
276: <span class="ruby-comment cmt"># Check other dialects</span>
|
|
||||||
277: <span class="ruby-identifier">lang</span>= <span class="ruby-node">"#{lang}_"</span>
|
|
||||||
278: <span class="ruby-constant">LOWERCASE_LANGUAGES</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">return</span> <span class="ruby-constant">LOWERCASE_LANGUAGES</span>[<span class="ruby-identifier">k</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">starts_with?</span>(<span class="ruby-identifier">lang</span>)}
|
|
||||||
279: <span class="ruby-comment cmt"># Nothing found</span>
|
|
||||||
280: <span class="ruby-keyword kw">nil</span>
|
|
||||||
281: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000018" class="method-detail">
|
|
||||||
<a name="M000018"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000018" class="method-signature">
|
|
||||||
<span class="method-name">valid_language?</span><span class="method-args">(language)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Returns <tt>true</tt> if there are any localized strings for a specified
|
|
||||||
language. Note that although <tt>set_langauge nil</tt> is perfectly valid,
|
|
||||||
<tt>nil</tt> is not a valid language.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000018-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000018-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 290</span>
|
|
||||||
290: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">valid_language?</span>(<span class="ruby-identifier">language</span>)
|
|
||||||
291: <span class="ruby-constant">LOCALIZED_STRINGS</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">language</span>.<span class="ruby-identifier">to_sym</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">false</span>
|
|
||||||
292: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000017" class="method-detail">
|
|
||||||
<a name="M000017"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000017" class="method-signature">
|
|
||||||
<span class="method-name">valid_languages</span><span class="method-args">()</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Returns an array of (currently) valid languages (ie. languages for which
|
|
||||||
localized data exists).
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000017-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 284</span>
|
|
||||||
284: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">valid_languages</span>
|
|
||||||
285: <span class="ruby-constant">LOCALIZED_STRINGS</span>.<span class="ruby-identifier">keys</span>
|
|
||||||
286: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h3 class="section-bar">Public Instance methods</h3>
|
|
||||||
|
|
||||||
<div id="method-M000002" class="method-detail">
|
|
||||||
<a name="M000002"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000002" class="method-signature">
|
|
||||||
<span class="method-name">current_language</span><span class="method-args">()</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Returns the instance-level current language, or if not set, returns the
|
|
||||||
class-level current language.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000002-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 77</span>
|
|
||||||
77: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">current_language</span>
|
|
||||||
78: <span class="ruby-ivar">@gloc_language</span> <span class="ruby-operator">||</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">current_language</span>
|
|
||||||
79: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Module: GLoc::ClassMethods</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="classHeader">
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Module</strong></td>
|
|
||||||
<td class="class-name-in-header">GLoc::ClassMethods</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>In:</strong></td>
|
|
||||||
<td>
|
|
||||||
<a href="../../files/lib/gloc_rb.html">
|
|
||||||
lib/gloc.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
All classes/modules that include <a href="../GLoc.html">GLoc</a> will also
|
|
||||||
gain these class methods. Notice that the <a
|
|
||||||
href="InstanceMethods.html">GLoc::InstanceMethods</a> module is also
|
|
||||||
included.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-list">
|
|
||||||
<h3 class="section-bar">Methods</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<a href="#M000019">current_language</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
<div id="includes">
|
|
||||||
<h3 class="section-bar">Included Modules</h3>
|
|
||||||
|
|
||||||
<div id="includes-list">
|
|
||||||
<span class="include-name"><a href="InstanceMethods.html">::GLoc::InstanceMethods</a></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
<div id="methods">
|
|
||||||
<h3 class="section-bar">Public Instance methods</h3>
|
|
||||||
|
|
||||||
<div id="method-M000019" class="method-detail">
|
|
||||||
<a name="M000019"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000019" class="method-signature">
|
|
||||||
<span class="method-name">current_language</span><span class="method-args">()</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Returns the current language, or if not set, returns the <a
|
|
||||||
href="../GLoc.html">GLoc</a> current language.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000019-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 89</span>
|
|
||||||
89: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">current_language</span>
|
|
||||||
90: <span class="ruby-ivar">@gloc_language</span> <span class="ruby-operator">||</span> <span class="ruby-constant">GLoc</span>.<span class="ruby-identifier">current_language</span>
|
|
||||||
91: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,323 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Module: GLoc::Helpers</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="classHeader">
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Module</strong></td>
|
|
||||||
<td class="class-name-in-header">GLoc::Helpers</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>In:</strong></td>
|
|
||||||
<td>
|
|
||||||
<a href="../../files/lib/gloc-helpers_rb.html">
|
|
||||||
lib/gloc-helpers.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
These helper methods will be included in the <a
|
|
||||||
href="InstanceMethods.html">InstanceMethods</a> module.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-list">
|
|
||||||
<h3 class="section-bar">Methods</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<a href="#M000026">l_YesNo</a>
|
|
||||||
<a href="#M000020">l_age</a>
|
|
||||||
<a href="#M000021">l_date</a>
|
|
||||||
<a href="#M000022">l_datetime</a>
|
|
||||||
<a href="#M000023">l_datetime_short</a>
|
|
||||||
<a href="#M000028">l_lang_name</a>
|
|
||||||
<a href="#M000024">l_strftime</a>
|
|
||||||
<a href="#M000025">l_time</a>
|
|
||||||
<a href="#M000027">l_yesno</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
<div id="methods">
|
|
||||||
<h3 class="section-bar">Public Instance methods</h3>
|
|
||||||
|
|
||||||
<div id="method-M000026" class="method-detail">
|
|
||||||
<a name="M000026"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000026" class="method-signature">
|
|
||||||
<span class="method-name">l_YesNo</span><span class="method-args">(value)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000026-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-helpers.rb, line 12</span>
|
|
||||||
12: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">l_YesNo</span>(<span class="ruby-identifier">value</span>) <span class="ruby-identifier">l</span>(<span class="ruby-identifier">value</span> <span class="ruby-value">? </span><span class="ruby-operator">:</span><span class="ruby-identifier">general_text_Yes</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:general_text_No</span>) <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000020" class="method-detail">
|
|
||||||
<a name="M000020"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000020" class="method-signature">
|
|
||||||
<span class="method-name">l_age</span><span class="method-args">(age)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000020-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-helpers.rb, line 6</span>
|
|
||||||
6: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">l_age</span>(<span class="ruby-identifier">age</span>) <span class="ruby-identifier">lwr</span> <span class="ruby-operator">:</span><span class="ruby-identifier">general_fmt_age</span>, <span class="ruby-identifier">age</span> <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000021" class="method-detail">
|
|
||||||
<a name="M000021"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000021" class="method-signature">
|
|
||||||
<span class="method-name">l_date</span><span class="method-args">(date)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000021-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-helpers.rb, line 7</span>
|
|
||||||
7: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">l_date</span>(<span class="ruby-identifier">date</span>) <span class="ruby-identifier">l_strftime</span> <span class="ruby-identifier">date</span>, <span class="ruby-identifier">:general_fmt_date</span> <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000022" class="method-detail">
|
|
||||||
<a name="M000022"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000022" class="method-signature">
|
|
||||||
<span class="method-name">l_datetime</span><span class="method-args">(date)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000022-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-helpers.rb, line 8</span>
|
|
||||||
8: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">l_datetime</span>(<span class="ruby-identifier">date</span>) <span class="ruby-identifier">l_strftime</span> <span class="ruby-identifier">date</span>, <span class="ruby-identifier">:general_fmt_datetime</span> <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000023" class="method-detail">
|
|
||||||
<a name="M000023"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000023" class="method-signature">
|
|
||||||
<span class="method-name">l_datetime_short</span><span class="method-args">(date)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000023-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-helpers.rb, line 9</span>
|
|
||||||
9: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">l_datetime_short</span>(<span class="ruby-identifier">date</span>) <span class="ruby-identifier">l_strftime</span> <span class="ruby-identifier">date</span>, <span class="ruby-identifier">:general_fmt_datetime_short</span> <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000028" class="method-detail">
|
|
||||||
<a name="M000028"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000028" class="method-signature">
|
|
||||||
<span class="method-name">l_lang_name</span><span class="method-args">(lang, display_lang=nil)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000028-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000028-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-helpers.rb, line 15</span>
|
|
||||||
15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">l_lang_name</span>(<span class="ruby-identifier">lang</span>, <span class="ruby-identifier">display_lang</span>=<span class="ruby-keyword kw">nil</span>)
|
|
||||||
16: <span class="ruby-identifier">ll</span> <span class="ruby-identifier">display_lang</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">current_language</span>, <span class="ruby-node">"general_lang_#{lang}"</span>
|
|
||||||
17: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000024" class="method-detail">
|
|
||||||
<a name="M000024"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000024" class="method-signature">
|
|
||||||
<span class="method-name">l_strftime</span><span class="method-args">(date,fmt)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000024-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-helpers.rb, line 10</span>
|
|
||||||
10: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">l_strftime</span>(<span class="ruby-identifier">date</span>,<span class="ruby-identifier">fmt</span>) <span class="ruby-identifier">date</span>.<span class="ruby-identifier">strftime</span> <span class="ruby-identifier">l</span>(<span class="ruby-identifier">fmt</span>) <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000025" class="method-detail">
|
|
||||||
<a name="M000025"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000025" class="method-signature">
|
|
||||||
<span class="method-name">l_time</span><span class="method-args">(time)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000025-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-helpers.rb, line 11</span>
|
|
||||||
11: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">l_time</span>(<span class="ruby-identifier">time</span>) <span class="ruby-identifier">l_strftime</span> <span class="ruby-identifier">time</span>, <span class="ruby-identifier">:general_fmt_time</span> <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000027" class="method-detail">
|
|
||||||
<a name="M000027"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000027" class="method-signature">
|
|
||||||
<span class="method-name">l_yesno</span><span class="method-args">(value)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000027-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000027-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc-helpers.rb, line 13</span>
|
|
||||||
13: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">l_yesno</span>(<span class="ruby-identifier">value</span>) <span class="ruby-identifier">l</span>(<span class="ruby-identifier">value</span> <span class="ruby-value">? </span><span class="ruby-operator">:</span><span class="ruby-identifier">general_text_yes</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:general_text_no</span>) <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,364 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Module: GLoc::InstanceMethods</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="classHeader">
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Module</strong></td>
|
|
||||||
<td class="class-name-in-header">GLoc::InstanceMethods</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>In:</strong></td>
|
|
||||||
<td>
|
|
||||||
<a href="../../files/lib/gloc_rb.html">
|
|
||||||
lib/gloc.rb
|
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
This module will be included in both instances and classes of <a
|
|
||||||
href="../GLoc.html">GLoc</a> includees. It is also included as class
|
|
||||||
methods in the <a href="../GLoc.html">GLoc</a> module itself.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-list">
|
|
||||||
<h3 class="section-bar">Methods</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
<a href="#M000029">l</a>
|
|
||||||
<a href="#M000034">l_has_string?</a>
|
|
||||||
<a href="#M000030">ll</a>
|
|
||||||
<a href="#M000031">ltry</a>
|
|
||||||
<a href="#M000032">lwr</a>
|
|
||||||
<a href="#M000033">lwr_</a>
|
|
||||||
<a href="#M000035">set_language</a>
|
|
||||||
<a href="#M000036">set_language_if_valid</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
<div id="includes">
|
|
||||||
<h3 class="section-bar">Included Modules</h3>
|
|
||||||
|
|
||||||
<div id="includes-list">
|
|
||||||
<span class="include-name"><a href="Helpers.html">Helpers</a></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
<div id="methods">
|
|
||||||
<h3 class="section-bar">Public Instance methods</h3>
|
|
||||||
|
|
||||||
<div id="method-M000029" class="method-detail">
|
|
||||||
<a name="M000029"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000029" class="method-signature">
|
|
||||||
<span class="method-name">l</span><span class="method-args">(symbol, *arguments)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Returns a localized string.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000029-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000029-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 18</span>
|
|
||||||
18: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">l</span>(<span class="ruby-identifier">symbol</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
|
|
||||||
19: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">GLoc</span>.<span class="ruby-identifier">_l</span>(<span class="ruby-identifier">symbol</span>,<span class="ruby-identifier">current_language</span>,<span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
|
|
||||||
20: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000034" class="method-detail">
|
|
||||||
<a name="M000034"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000034" class="method-signature">
|
|
||||||
<span class="method-name">l_has_string?</span><span class="method-args">(symbol)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Returns <tt>true</tt> if a localized string with the specified key exists.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000034-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000034-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 48</span>
|
|
||||||
48: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">l_has_string?</span>(<span class="ruby-identifier">symbol</span>)
|
|
||||||
49: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">GLoc</span>.<span class="ruby-identifier">_l_has_string?</span>(<span class="ruby-identifier">symbol</span>,<span class="ruby-identifier">current_language</span>)
|
|
||||||
50: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000030" class="method-detail">
|
|
||||||
<a name="M000030"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000030" class="method-signature">
|
|
||||||
<span class="method-name">ll</span><span class="method-args">(lang, symbol, *arguments)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Returns a localized string in a specified language. This does not effect
|
|
||||||
<tt>current_language</tt>.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000030-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000030-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 24</span>
|
|
||||||
24: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ll</span>(<span class="ruby-identifier">lang</span>, <span class="ruby-identifier">symbol</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
|
|
||||||
25: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">GLoc</span>.<span class="ruby-identifier">_l</span>(<span class="ruby-identifier">symbol</span>,<span class="ruby-identifier">lang</span>.<span class="ruby-identifier">to_sym</span>,<span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
|
|
||||||
26: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000031" class="method-detail">
|
|
||||||
<a name="M000031"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000031" class="method-signature">
|
|
||||||
<span class="method-name">ltry</span><span class="method-args">(possible_key)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Returns a localized string if the argument is a Symbol, else just returns
|
|
||||||
the argument.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000031-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000031-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 29</span>
|
|
||||||
29: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ltry</span>(<span class="ruby-identifier">possible_key</span>)
|
|
||||||
30: <span class="ruby-identifier">possible_key</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">l</span>(<span class="ruby-identifier">possible_key</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">possible_key</span>
|
|
||||||
31: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000032" class="method-detail">
|
|
||||||
<a name="M000032"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000032" class="method-signature">
|
|
||||||
<span class="method-name">lwr</span><span class="method-args">(symbol, *arguments)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Uses the default <a href="../GLoc.html">GLoc</a> rule to return a localized
|
|
||||||
string. See lwr_() for more info.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000032-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000032-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 35</span>
|
|
||||||
35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">lwr</span>(<span class="ruby-identifier">symbol</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
|
|
||||||
36: <span class="ruby-identifier">lwr_</span>(<span class="ruby-identifier">:default</span>, <span class="ruby-identifier">symbol</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
|
|
||||||
37: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000033" class="method-detail">
|
|
||||||
<a name="M000033"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000033" class="method-signature">
|
|
||||||
<span class="method-name">lwr_</span><span class="method-args">(rule, symbol, *arguments)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Uses a <em>rule</em> to return a localized string. A rule is a function
|
|
||||||
that uses specified arguments to return a localization key prefix. The
|
|
||||||
prefix is appended to the localization key originally specified, to create
|
|
||||||
a new key which is then used to lookup a localized string.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000033-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000033-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 43</span>
|
|
||||||
43: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">lwr_</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">symbol</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
|
|
||||||
44: <span class="ruby-constant">GLoc</span>.<span class="ruby-identifier">_l</span>(<span class="ruby-node">"#{symbol}#{GLoc::_l_rule(rule,current_language).call(*arguments)}"</span>,<span class="ruby-identifier">current_language</span>,<span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
|
|
||||||
45: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000035" class="method-detail">
|
|
||||||
<a name="M000035"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000035" class="method-signature">
|
|
||||||
<span class="method-name">set_language</span><span class="method-args">(language)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Sets the current language for this instance/class. Setting the language of
|
|
||||||
a class effects all instances unless the instance has its own language
|
|
||||||
defined.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000035-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 54</span>
|
|
||||||
54: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_language</span>(<span class="ruby-identifier">language</span>)
|
|
||||||
55: <span class="ruby-ivar">@gloc_language</span>= <span class="ruby-identifier">language</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">language</span>.<span class="ruby-identifier">to_sym</span>
|
|
||||||
56: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="method-M000036" class="method-detail">
|
|
||||||
<a name="M000036"></a>
|
|
||||||
|
|
||||||
<div class="method-heading">
|
|
||||||
<a href="#M000036" class="method-signature">
|
|
||||||
<span class="method-name">set_language_if_valid</span><span class="method-args">(language)</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="method-description">
|
|
||||||
<p>
|
|
||||||
Sets the current language if the language passed is a valid language. If
|
|
||||||
the language was valid, this method returns <tt>true</tt> else it will
|
|
||||||
return <tt>false</tt>. Note that <tt>nil</tt> is not a valid language. See
|
|
||||||
<a href="InstanceMethods.html#M000035">set_language</a>(language) for more
|
|
||||||
info.
|
|
||||||
</p>
|
|
||||||
<p><a class="source-toggle" href="#"
|
|
||||||
onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
|
|
||||||
<div class="method-source-code" id="M000036-source">
|
|
||||||
<pre>
|
|
||||||
<span class="ruby-comment cmt"># File lib/gloc.rb, line 62</span>
|
|
||||||
62: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_language_if_valid</span>(<span class="ruby-identifier">language</span>)
|
|
||||||
63: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">GLoc</span>.<span class="ruby-identifier">valid_language?</span>(<span class="ruby-identifier">language</span>)
|
|
||||||
64: <span class="ruby-identifier">set_language</span>(<span class="ruby-identifier">language</span>)
|
|
||||||
65: <span class="ruby-keyword kw">true</span>
|
|
||||||
66: <span class="ruby-keyword kw">else</span>
|
|
||||||
67: <span class="ruby-keyword kw">false</span>
|
|
||||||
68: <span class="ruby-keyword kw">end</span>
|
|
||||||
69: <span class="ruby-keyword kw">end</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Sun May 28 15:21:13 E. Australia Standard Time 2006
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>File: CHANGELOG</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="fileHeader">
|
|
||||||
<h1>CHANGELOG</h1>
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Path:</strong></td>
|
|
||||||
<td>CHANGELOG
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Last Update:</strong></td>
|
|
||||||
<td>Sun May 28 15:19:38 E. Australia Standard Time 2006</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<h2>Version 1.1 (28 May 2006)</h2>
|
|
||||||
<ul>
|
|
||||||
<li>The charset for each and/or all languages can now be easily configured.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Added a ActionController filter that auto-detects the client language.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>The rake task "sort" now merges lines that match 100%, and warns
|
|
||||||
if duplicate keys are found.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Rule support. Create flexible rules to handle issues such as pluralization.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Massive speed and stability improvements to development mode.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Added Russian strings. (Thanks to Evgeny Lineytsev)
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Complete RDoc documentation.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Improved helpers.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li><a href="../classes/GLoc.html">GLoc</a> now configurable via get_config and
|
|
||||||
set_config
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Added an option to tell <a href="../classes/GLoc.html">GLoc</a> to output
|
|
||||||
various verbose information.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>More useful functions such as set_language_if_valid, similar_language
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li><a href="../classes/GLoc.html">GLoc</a>’s entire internal state can
|
|
||||||
now be backed up and restored.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<h2>Version 1.0 (17 April 2006)</h2>
|
|
||||||
<ul>
|
|
||||||
<li>Initial public release.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,480 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>File: README</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="fileHeader">
|
|
||||||
<h1>README</h1>
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Path:</strong></td>
|
|
||||||
<td>README
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Last Update:</strong></td>
|
|
||||||
<td>Sun May 28 15:19:38 E. Australia Standard Time 2006</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<h1>About</h1>
|
|
||||||
<h3>Preface</h3>
|
|
||||||
<p>
|
|
||||||
I originally started designing this on weekends and after work in 2005. We
|
|
||||||
started to become very interested in Rails at work and I wanted to get some
|
|
||||||
experience with ruby with before we started using it full-time. I
|
|
||||||
didn’t have very many ideas for anything interesting to create so,
|
|
||||||
because we write a lot of multilingual webapps at my company, I decided to
|
|
||||||
write a localization library. That way if my little hobby project developed
|
|
||||||
into something decent, I could at least put it to good use. And here we are
|
|
||||||
in 2006, my little hobby project has come a long way and become quite a
|
|
||||||
useful piece of software. Not only do I use it in production sites I write
|
|
||||||
at work, but I also prefer it to other existing alternatives. Therefore I
|
|
||||||
have decided to make it publicly available, and I hope that other
|
|
||||||
developers will find it useful too.
|
|
||||||
</p>
|
|
||||||
<h3>About</h3>
|
|
||||||
<p>
|
|
||||||
<a href="../classes/GLoc.html">GLoc</a> is a localization library. It
|
|
||||||
doesn’t aim to do everything l10n-related that you can imagine, but
|
|
||||||
what it does, it does very well. It was originally designed as a Rails
|
|
||||||
plugin, but can also be used for plain ruby projects. Here are a list of
|
|
||||||
its main features:
|
|
||||||
</p>
|
|
||||||
<ul>
|
|
||||||
<li>Lightweight and efficient.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Uses file-based string bundles. Strings can also be set directly.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Intelligent, cascading language configuration.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Create flexible rules to handle issues such as pluralization.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Includes a ActionController filter that auto-detects the client language.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Works perfectly with Rails Engines and allows strings to be overridden just
|
|
||||||
as easily as controllers, models, etc.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Automatically localizes Rails functions such as distance_in_minutes,
|
|
||||||
select_month etc
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Supports different charsets. You can even specify the encoding to use for
|
|
||||||
each language seperately.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Special Rails mods/helpers.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<h3>What does <a href="../classes/GLoc.html">GLoc</a> mean?</h3>
|
|
||||||
<p>
|
|
||||||
If you’re wondering about the name "<a
|
|
||||||
href="../classes/GLoc.html">GLoc</a>", I’m sure you’re not
|
|
||||||
alone. This project was originally just called "Localization"
|
|
||||||
which was a bit too common, so when I decided to release it I decided to
|
|
||||||
call it "Golly’s Localization Library" instead (Golly is my
|
|
||||||
nickname), and that was long and boring so I then abbreviated that to
|
|
||||||
"<a href="../classes/GLoc.html">GLoc</a>". What a fun story!!
|
|
||||||
</p>
|
|
||||||
<h3>Localization helpers</h3>
|
|
||||||
<p>
|
|
||||||
This also includes a few helpers for common situations such as displaying
|
|
||||||
localized date, time, "yes" or "no", etc.
|
|
||||||
</p>
|
|
||||||
<h3>Rails Localization</h3>
|
|
||||||
<p>
|
|
||||||
At the moment, unless you manually remove the <tt>require
|
|
||||||
‘gloc-rails-text’</tt> line from init.rb, this plugin overrides
|
|
||||||
certain Rails functions to provide multilingual versions. This
|
|
||||||
automatically localizes functions such as select_date(),
|
|
||||||
distance_of_time_in_words() and more… The strings can be found in
|
|
||||||
lang/*.yml. NOTE: This is not complete. Timezones and countries are not
|
|
||||||
currently localized.
|
|
||||||
</p>
|
|
||||||
<h1>Usage</h1>
|
|
||||||
<h3>Quickstart</h3>
|
|
||||||
<p>
|
|
||||||
Windows users will need to first install iconv. <a
|
|
||||||
href="http://wiki.rubyonrails.com/rails/pages/iconv">wiki.rubyonrails.com/rails/pages/iconv</a>
|
|
||||||
</p>
|
|
||||||
<ul>
|
|
||||||
<li>Create a dir "#{RAILS_ROOT}/lang"
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Create a file "#{RAILS_ROOT}/lang/en.yml" and write your strings.
|
|
||||||
The format is "key: string". Save it as UTF-8. If you save it in
|
|
||||||
a different encoding, add a key called file_charset (eg.
|
|
||||||
"file_charset: iso-2022-jp")
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Put the following in config/environment.rb and change the values as you see
|
|
||||||
fit. The following example is for an app that uses English and Japanese,
|
|
||||||
with Japanese being the default.
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
GLoc.set_config :default_language => :ja
|
|
||||||
GLoc.clear_strings_except :en, :ja
|
|
||||||
GLoc.set_kcode
|
|
||||||
GLoc.load_localized_strings
|
|
||||||
</pre>
|
|
||||||
</li>
|
|
||||||
<li>Add ‘include <a href="../classes/GLoc.html">GLoc</a>’ to all
|
|
||||||
classes that will use localization. This is added to most Rails classes
|
|
||||||
automatically.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>Optionally, you can set the language for models and controllers by simply
|
|
||||||
inserting <tt>set_language :en</tt> in classes and/or methods.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>To use localized strings, replace text such as <tt>"Welcome"</tt>
|
|
||||||
with <tt>l(:welcome_string_key)</tt>, and <tt>"Hello
|
|
||||||
#{name}."</tt> with <tt>l(:hello_string_key, name)</tt>. (Of course
|
|
||||||
the strings will need to exist in your string bundle.)
|
|
||||||
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<p>
|
|
||||||
There is more functionality provided by this plugin, that is not
|
|
||||||
demonstrated above. Please read the API summary for details.
|
|
||||||
</p>
|
|
||||||
<h3>API summary</h3>
|
|
||||||
<p>
|
|
||||||
The following methods are added as both class methods and instance methods
|
|
||||||
to modules/classes that include <a href="../classes/GLoc.html">GLoc</a>.
|
|
||||||
They are also available as class methods of <a
|
|
||||||
href="../classes/GLoc.html">GLoc</a>.
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
current_language # Returns the current language
|
|
||||||
l(symbol, *arguments) # Returns a localized string
|
|
||||||
ll(lang, symbol, *arguments) # Returns a localized string in a specific language
|
|
||||||
ltry(possible_key) # Returns a localized string if passed a Symbol, else returns the same argument passed
|
|
||||||
lwr(symbol, *arguments) # Uses the default rule to return a localized string.
|
|
||||||
lwr_(rule, symbol, *arguments) # Uses a specified rule to return a localized string.
|
|
||||||
l_has_string?(symbol) # Checks if a localized string exists
|
|
||||||
set_language(language) # Sets the language for the current class or class instance
|
|
||||||
set_language_if_valid(lang) # Sets the current language if the language passed is a valid language
|
|
||||||
</pre>
|
|
||||||
<p>
|
|
||||||
The <a href="../classes/GLoc.html">GLoc</a> module also defines the
|
|
||||||
following class methods:
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
add_localized_strings(lang, symbol_hash, override=true) # Adds a hash of localized strings
|
|
||||||
backup_state(clear=false) # Creates a backup of GLoc's internal state and optionally clears everything too
|
|
||||||
clear_strings(*languages) # Removes localized strings from memory
|
|
||||||
clear_strings_except(*languages) # Removes localized strings from memory except for those of certain specified languages
|
|
||||||
get_charset(lang) # Returns the charset used to store localized strings in memory
|
|
||||||
get_config(key) # Returns a GLoc configuration value (see below)
|
|
||||||
load_localized_strings(dir=nil, override=true) # Loads localized strings from all YML files in a given directory
|
|
||||||
restore_state(state) # Restores a backup of GLoc's internal state
|
|
||||||
set_charset(new_charset, *langs) # Sets the charset used to internally store localized strings
|
|
||||||
set_config(hash) # Sets GLoc configuration values (see below)
|
|
||||||
set_kcode(charset=nil) # Sets the $KCODE global variable
|
|
||||||
similar_language(language) # Tries to find a valid language that is similar to the argument passed
|
|
||||||
valid_languages # Returns an array of (currently) valid languages (ie. languages for which localized data exists)
|
|
||||||
valid_language?(language) # Checks whether any localized strings are in memory for a given language
|
|
||||||
</pre>
|
|
||||||
<p>
|
|
||||||
<a href="../classes/GLoc.html">GLoc</a> uses the following configuration
|
|
||||||
items. They can be accessed via <tt>get_config</tt> and
|
|
||||||
<tt>set_config</tt>.
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
:default_cookie_name
|
|
||||||
:default_language
|
|
||||||
:default_param_name
|
|
||||||
:raise_string_not_found_errors
|
|
||||||
:verbose
|
|
||||||
</pre>
|
|
||||||
<p>
|
|
||||||
The <a href="../classes/GLoc.html">GLoc</a> module is automatically
|
|
||||||
included in the following classes:
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
ActionController::Base
|
|
||||||
ActionMailer::Base
|
|
||||||
ActionView::Base
|
|
||||||
ActionView::Helpers::InstanceTag
|
|
||||||
ActiveRecord::Base
|
|
||||||
ActiveRecord::Errors
|
|
||||||
ApplicationHelper
|
|
||||||
Test::Unit::TestCase
|
|
||||||
</pre>
|
|
||||||
<p>
|
|
||||||
The <a href="../classes/GLoc.html">GLoc</a> module also defines the
|
|
||||||
following controller filters:
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
autodetect_language_filter
|
|
||||||
</pre>
|
|
||||||
<p>
|
|
||||||
<a href="../classes/GLoc.html">GLoc</a> also makes the following change to
|
|
||||||
Rails:
|
|
||||||
</p>
|
|
||||||
<ul>
|
|
||||||
<li>Views for ActionMailer are now #{view_name}_#{language}.rb rather than just
|
|
||||||
#{view_name}.rb
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li>All ActiveRecord validation class methods now accept a localized string key
|
|
||||||
(symbol) as a :message value.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li><a
|
|
||||||
href="../classes/ActiveRecord/Errors.html#M000039">ActiveRecord::Errors.add</a>
|
|
||||||
now accepts symbols as valid message values. At runtime these symbols are
|
|
||||||
converted to localized strings using the current_language of the base
|
|
||||||
record.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
<li><a
|
|
||||||
href="../classes/ActiveRecord/Errors.html#M000039">ActiveRecord::Errors.add</a>
|
|
||||||
now accepts arrays as arguments so that printf-style strings can be
|
|
||||||
generated at runtime. This also applies to the validates_* class methods.
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
Eg. validates_xxxxxx_of :name, :message => ['Your name must be at least %d characters.', MIN_LEN]
|
|
||||||
Eg. validates_xxxxxx_of :name, :message => [:user_error_validation_name_too_short, MIN_LEN]
|
|
||||||
</pre>
|
|
||||||
</li>
|
|
||||||
<li>Instances of ActiveView inherit their current_language from the controller
|
|
||||||
(or mailer) creating them.
|
|
||||||
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<p>
|
|
||||||
This plugin also adds the following rake tasks:
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
* gloc:sort - Sorts the keys in the lang ymls (also accepts a DIR argument)
|
|
||||||
</pre>
|
|
||||||
<h3>Cascading language configuration</h3>
|
|
||||||
<p>
|
|
||||||
The language can be set at three levels:
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
1. The default # GLoc.get_config :default_language
|
|
||||||
2. Class level # class A; set_language :de; end
|
|
||||||
3. Instance level # b= B.new; b.set_language :zh
|
|
||||||
</pre>
|
|
||||||
<p>
|
|
||||||
Instance level has the highest priority and the default has the lowest.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Because <a href="../classes/GLoc.html">GLoc</a> is included at class level
|
|
||||||
too, it becomes easy to associate languages with contexts. For example:
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
class Student
|
|
||||||
set_language :en
|
|
||||||
def say_hello
|
|
||||||
puts "We say #{l :hello} but our teachers say #{Teacher.l :hello}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
</pre>
|
|
||||||
<h3>Rules</h3>
|
|
||||||
<p>
|
|
||||||
There are often situations when depending on the value of one or more
|
|
||||||
variables, the surrounding text changes. The most common case of this is
|
|
||||||
pluralization. Rather than hardcode these rules, they are completely
|
|
||||||
definable by the user so that the user can eaasily accomodate for more
|
|
||||||
complicated grammatical rules such as those found in Russian and Polish (or
|
|
||||||
so I hear). To define a rule, simply include a string in the string bundle
|
|
||||||
whose key begins with "<em>gloc_rule</em>" and then write ruby
|
|
||||||
code as the value. The ruby code will be converted to a Proc when the
|
|
||||||
string bundle is first read, and should return a prefix that will be
|
|
||||||
appended to the string key at runtime to point to a new string. Make sense?
|
|
||||||
Probably not… Please look at the following example and I am sure it
|
|
||||||
will all make sense.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Simple example (string bundle / en.yml)
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
_gloc_rule_default: ' |n| n==1 ? "_single" : "_plural" '
|
|
||||||
man_count_plural: There are %d men.
|
|
||||||
man_count_single: There is 1 man.
|
|
||||||
</pre>
|
|
||||||
<p>
|
|
||||||
Simple example (code)
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
lwr(:man_count, 1) # => There is 1 man.
|
|
||||||
lwr(:man_count, 8) # => There are 8 men.
|
|
||||||
</pre>
|
|
||||||
<p>
|
|
||||||
To use rules other than the default simply call lwr_ instead of lwr, and
|
|
||||||
specify the rule.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Example 2 (string bundle / en.yml)
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
_gloc_rule_default: ' |n| n==1 ? "_single" : "_plural" '
|
|
||||||
_gloc_rule_custom: ' |n| return "_none" if n==0; return "_heaps" if n>100; n==1 ? "_single" : "_plural" '
|
|
||||||
man_count_none: There are no men.
|
|
||||||
man_count_heaps: There are heaps of men!!
|
|
||||||
man_count_plural: There are %d men.
|
|
||||||
man_count_single: There is 1 man.
|
|
||||||
</pre>
|
|
||||||
<p>
|
|
||||||
Example 2 (code)
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
lwr_(:custom, :man_count, 0) # => There are no men.
|
|
||||||
lwr_(:custom, :man_count, 1) # => There is 1 man.
|
|
||||||
lwr_(:custom, :man_count, 8) # => There are 8 men.
|
|
||||||
lwr_(:custom, :man_count, 150) # => There are heaps of men!!
|
|
||||||
</pre>
|
|
||||||
<h3>Helpers</h3>
|
|
||||||
<p>
|
|
||||||
<a href="../classes/GLoc.html">GLoc</a> includes the following helpers:
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
l_age(age) # Returns a localized version of an age. eg "3 years old"
|
|
||||||
l_date(date) # Returns a date in a localized format
|
|
||||||
l_datetime(date) # Returns a date+time in a localized format
|
|
||||||
l_datetime_short(date) # Returns a date+time in a localized short format.
|
|
||||||
l_lang_name(l,dl=nil) # Returns the name of a language (you must supply your own strings)
|
|
||||||
l_strftime(date,fmt) # Formats a date/time in a localized format.
|
|
||||||
l_time(date) # Returns a time in a localized format
|
|
||||||
l_YesNo(value) # Returns localized string of "Yes" or "No" depending on the arg
|
|
||||||
l_yesno(value) # Returns localized string of "yes" or "no" depending on the arg
|
|
||||||
</pre>
|
|
||||||
<h3>Rails localization</h3>
|
|
||||||
<p>
|
|
||||||
Not all of Rails is covered but the following functions are:
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
distance_of_time_in_words
|
|
||||||
select_day
|
|
||||||
select_month
|
|
||||||
select_year
|
|
||||||
add_options
|
|
||||||
</pre>
|
|
||||||
<h1>FAQ</h1>
|
|
||||||
<h4>How do I use it in engines?</h4>
|
|
||||||
<p>
|
|
||||||
Simply put this in your init_engine.rb
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
GLoc.load_localized_strings File.join(File.dirname(__FILE__),'lang')
|
|
||||||
</pre>
|
|
||||||
<p>
|
|
||||||
That way your engines strings will be loaded when the engine is started.
|
|
||||||
Just simply make sure that you load your application strings after you
|
|
||||||
start your engines to safely override any engine strings.
|
|
||||||
</p>
|
|
||||||
<h4>Why am I getting an Iconv::IllegalSequence error when calling <a href="../classes/GLoc.html#M000013">GLoc.set_charset</a>?</h4>
|
|
||||||
<p>
|
|
||||||
By default <a href="../classes/GLoc.html">GLoc</a> loads all of its default
|
|
||||||
strings at startup. For example, calling <tt>set_charset
|
|
||||||
‘iso-2022-jp’</tt> will cause this error because Russian
|
|
||||||
strings are loaded by default, and the Russian strings use characters that
|
|
||||||
cannot be expressed in the ISO-2022-JP charset. Before calling
|
|
||||||
<tt>set_charset</tt> you should call <tt>clear_strings_except</tt> to
|
|
||||||
remove strings from any languages that you will not be using.
|
|
||||||
Alternatively, you can simply specify the language(s) as follows,
|
|
||||||
<tt>set_charset ‘iso-2022-jp’, :ja</tt>.
|
|
||||||
</p>
|
|
||||||
<h4>How do I make <a href="../classes/GLoc.html">GLoc</a> ignore StringNotFoundErrors?</h4>
|
|
||||||
<p>
|
|
||||||
Disable it as follows:
|
|
||||||
</p>
|
|
||||||
<pre>
|
|
||||||
GLoc.set_config :raise_string_not_found_errors => false
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>File: gloc-helpers.rb</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="fileHeader">
|
|
||||||
<h1>gloc-helpers.rb</h1>
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Path:</strong></td>
|
|
||||||
<td>lib/gloc-helpers.rb
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Last Update:</strong></td>
|
|
||||||
<td>Sun May 28 15:19:38 E. Australia Standard Time 2006</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
Copyright © 2005-2006 David Barri
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>File: gloc-internal.rb</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="fileHeader">
|
|
||||||
<h1>gloc-internal.rb</h1>
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Path:</strong></td>
|
|
||||||
<td>lib/gloc-internal.rb
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Last Update:</strong></td>
|
|
||||||
<td>Sun May 28 15:19:38 E. Australia Standard Time 2006</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
Copyright © 2005-2006 David Barri
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="requires-list">
|
|
||||||
<h3 class="section-bar">Required files</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
iconv
|
|
||||||
gloc-version
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>File: gloc-rails-text.rb</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="fileHeader">
|
|
||||||
<h1>gloc-rails-text.rb</h1>
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Path:</strong></td>
|
|
||||||
<td>lib/gloc-rails-text.rb
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Last Update:</strong></td>
|
|
||||||
<td>Sun May 28 15:19:38 E. Australia Standard Time 2006</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
Copyright © 2005-2006 David Barri
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="requires-list">
|
|
||||||
<h3 class="section-bar">Required files</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
date
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>File: gloc-rails.rb</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="fileHeader">
|
|
||||||
<h1>gloc-rails.rb</h1>
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Path:</strong></td>
|
|
||||||
<td>lib/gloc-rails.rb
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Last Update:</strong></td>
|
|
||||||
<td>Sun May 28 15:19:38 E. Australia Standard Time 2006</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
Copyright © 2005-2006 David Barri
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="requires-list">
|
|
||||||
<h3 class="section-bar">Required files</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
gloc
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>File: gloc-ruby.rb</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="fileHeader">
|
|
||||||
<h1>gloc-ruby.rb</h1>
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Path:</strong></td>
|
|
||||||
<td>lib/gloc-ruby.rb
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Last Update:</strong></td>
|
|
||||||
<td>Sun May 28 15:19:38 E. Australia Standard Time 2006</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
Copyright © 2005-2006 David Barri
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>File: gloc-version.rb</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="fileHeader">
|
|
||||||
<h1>gloc-version.rb</h1>
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Path:</strong></td>
|
|
||||||
<td>lib/gloc-version.rb
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Last Update:</strong></td>
|
|
||||||
<td>Sun May 28 15:19:38 E. Australia Standard Time 2006</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>File: gloc.rb</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
||||||
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
// <![CDATA[
|
|
||||||
|
|
||||||
function popupCode( url ) {
|
|
||||||
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCode( id ) {
|
|
||||||
if ( document.getElementById )
|
|
||||||
elem = document.getElementById( id );
|
|
||||||
else if ( document.all )
|
|
||||||
elem = eval( "document.all." + id );
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
elemStyle = elem.style;
|
|
||||||
|
|
||||||
if ( elemStyle.display != "block" ) {
|
|
||||||
elemStyle.display = "block"
|
|
||||||
} else {
|
|
||||||
elemStyle.display = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make codeblocks hidden by default
|
|
||||||
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
||||||
|
|
||||||
// ]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="fileHeader">
|
|
||||||
<h1>gloc.rb</h1>
|
|
||||||
<table class="header-table">
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Path:</strong></td>
|
|
||||||
<td>lib/gloc.rb
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="top-aligned-row">
|
|
||||||
<td><strong>Last Update:</strong></td>
|
|
||||||
<td>Sun May 28 15:19:38 E. Australia Standard Time 2006</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- banner header -->
|
|
||||||
|
|
||||||
<div id="bodyContent">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div id="contextContent">
|
|
||||||
|
|
||||||
<div id="description">
|
|
||||||
<p>
|
|
||||||
Copyright © 2005-2006 David Barri
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="requires-list">
|
|
||||||
<h3 class="section-bar">Required files</h3>
|
|
||||||
|
|
||||||
<div class="name-list">
|
|
||||||
yaml
|
|
||||||
gloc-internal
|
|
||||||
gloc-helpers
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if includes -->
|
|
||||||
|
|
||||||
<div id="section">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- if method_list -->
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="validator-badges">
|
|
||||||
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
|
|
||||||
<?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">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
Classes
|
|
||||||
|
|
||||||
-->
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Classes</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
|
|
||||||
<base target="docwin" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="index">
|
|
||||||
<h1 class="section-bar">Classes</h1>
|
|
||||||
<div id="index-entries">
|
|
||||||
<a href="classes/ActionController/Filters/ClassMethods.html">ActionController::Filters::ClassMethods</a><br />
|
|
||||||
<a href="classes/ActionMailer/Base.html">ActionMailer::Base</a><br />
|
|
||||||
<a href="classes/ActionView/Base.html">ActionView::Base</a><br />
|
|
||||||
<a href="classes/ActionView/Helpers/DateHelper.html">ActionView::Helpers::DateHelper</a><br />
|
|
||||||
<a href="classes/ActionView/Helpers/InstanceTag.html">ActionView::Helpers::InstanceTag</a><br />
|
|
||||||
<a href="classes/ActiveRecord/Errors.html">ActiveRecord::Errors</a><br />
|
|
||||||
<a href="classes/ActiveRecord/Validations/ClassMethods.html">ActiveRecord::Validations::ClassMethods</a><br />
|
|
||||||
<a href="classes/GLoc.html">GLoc</a><br />
|
|
||||||
<a href="classes/GLoc/ClassMethods.html">GLoc::ClassMethods</a><br />
|
|
||||||
<a href="classes/GLoc/Helpers.html">GLoc::Helpers</a><br />
|
|
||||||
<a href="classes/GLoc/InstanceMethods.html">GLoc::InstanceMethods</a><br />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
|
|
||||||
<?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">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
Files
|
|
||||||
|
|
||||||
-->
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Files</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
|
|
||||||
<base target="docwin" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="index">
|
|
||||||
<h1 class="section-bar">Files</h1>
|
|
||||||
<div id="index-entries">
|
|
||||||
<a href="files/CHANGELOG.html">CHANGELOG</a><br />
|
|
||||||
<a href="files/README.html">README</a><br />
|
|
||||||
<a href="files/lib/gloc-helpers_rb.html">lib/gloc-helpers.rb</a><br />
|
|
||||||
<a href="files/lib/gloc-internal_rb.html">lib/gloc-internal.rb</a><br />
|
|
||||||
<a href="files/lib/gloc-rails-text_rb.html">lib/gloc-rails-text.rb</a><br />
|
|
||||||
<a href="files/lib/gloc-rails_rb.html">lib/gloc-rails.rb</a><br />
|
|
||||||
<a href="files/lib/gloc-ruby_rb.html">lib/gloc-ruby.rb</a><br />
|
|
||||||
<a href="files/lib/gloc-version_rb.html">lib/gloc-version.rb</a><br />
|
|
||||||
<a href="files/lib/gloc_rb.html">lib/gloc.rb</a><br />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
|
|
||||||
<?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">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
Methods
|
|
||||||
|
|
||||||
-->
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Methods</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
|
|
||||||
<base target="docwin" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="index">
|
|
||||||
<h1 class="section-bar">Methods</h1>
|
|
||||||
<div id="index-entries">
|
|
||||||
<a href="classes/ActiveRecord/Errors.html#M000039">add (ActiveRecord::Errors)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000004">add_localized_strings (GLoc)</a><br />
|
|
||||||
<a href="classes/ActionController/Filters/ClassMethods.html#M000001">autodetect_language_filter (ActionController::Filters::ClassMethods)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000005">backup_state (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000006">clear_strings (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000007">clear_strings_except (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc/ClassMethods.html#M000019">current_language (GLoc::ClassMethods)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000003">current_language (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000002">current_language (GLoc)</a><br />
|
|
||||||
<a href="classes/ActionView/Helpers/InstanceTag.html#M000045">current_language (ActionView::Helpers::InstanceTag)</a><br />
|
|
||||||
<a href="classes/ActiveRecord/Errors.html#M000040">current_language (ActiveRecord::Errors)</a><br />
|
|
||||||
<a href="classes/ActionView/Helpers/DateHelper.html#M000041">distance_of_time_in_words (ActionView::Helpers::DateHelper)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000008">get_charset (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000009">get_config (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc/InstanceMethods.html#M000029">l (GLoc::InstanceMethods)</a><br />
|
|
||||||
<a href="classes/GLoc/Helpers.html#M000026">l_YesNo (GLoc::Helpers)</a><br />
|
|
||||||
<a href="classes/GLoc/Helpers.html#M000020">l_age (GLoc::Helpers)</a><br />
|
|
||||||
<a href="classes/GLoc/Helpers.html#M000021">l_date (GLoc::Helpers)</a><br />
|
|
||||||
<a href="classes/GLoc/Helpers.html#M000022">l_datetime (GLoc::Helpers)</a><br />
|
|
||||||
<a href="classes/GLoc/Helpers.html#M000023">l_datetime_short (GLoc::Helpers)</a><br />
|
|
||||||
<a href="classes/GLoc/InstanceMethods.html#M000034">l_has_string? (GLoc::InstanceMethods)</a><br />
|
|
||||||
<a href="classes/GLoc/Helpers.html#M000028">l_lang_name (GLoc::Helpers)</a><br />
|
|
||||||
<a href="classes/GLoc/Helpers.html#M000024">l_strftime (GLoc::Helpers)</a><br />
|
|
||||||
<a href="classes/GLoc/Helpers.html#M000025">l_time (GLoc::Helpers)</a><br />
|
|
||||||
<a href="classes/GLoc/Helpers.html#M000027">l_yesno (GLoc::Helpers)</a><br />
|
|
||||||
<a href="classes/GLoc/InstanceMethods.html#M000030">ll (GLoc::InstanceMethods)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000010">load_gloc_default_localized_strings (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000011">load_localized_strings (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc/InstanceMethods.html#M000031">ltry (GLoc::InstanceMethods)</a><br />
|
|
||||||
<a href="classes/GLoc/InstanceMethods.html#M000032">lwr (GLoc::InstanceMethods)</a><br />
|
|
||||||
<a href="classes/GLoc/InstanceMethods.html#M000033">lwr_ (GLoc::InstanceMethods)</a><br />
|
|
||||||
<a href="classes/ActionView/Base.html#M000046">new (ActionView::Base)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000012">restore_state (GLoc)</a><br />
|
|
||||||
<a href="classes/ActionView/Helpers/DateHelper.html#M000042">select_day (ActionView::Helpers::DateHelper)</a><br />
|
|
||||||
<a href="classes/ActionView/Helpers/DateHelper.html#M000043">select_month (ActionView::Helpers::DateHelper)</a><br />
|
|
||||||
<a href="classes/ActionView/Helpers/DateHelper.html#M000044">select_year (ActionView::Helpers::DateHelper)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000013">set_charset (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000014">set_config (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000015">set_kcode (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc/InstanceMethods.html#M000035">set_language (GLoc::InstanceMethods)</a><br />
|
|
||||||
<a href="classes/GLoc/InstanceMethods.html#M000036">set_language_if_valid (GLoc::InstanceMethods)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000016">similar_language (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000018">valid_language? (GLoc)</a><br />
|
|
||||||
<a href="classes/GLoc.html#M000017">valid_languages (GLoc)</a><br />
|
|
||||||
<a href="classes/ActiveRecord/Validations/ClassMethods.html#M000037">validates_length_of (ActiveRecord::Validations::ClassMethods)</a><br />
|
|
||||||
<a href="classes/ActiveRecord/Validations/ClassMethods.html#M000038">validates_size_of (ActiveRecord::Validations::ClassMethods)</a><br />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
||||||
<!DOCTYPE html
|
|
||||||
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
GLoc Localization Library Documentation
|
|
||||||
|
|
||||||
-->
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head>
|
|
||||||
<title>GLoc Localization Library Documentation</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
||||||
</head>
|
|
||||||
<frameset rows="20%, 80%">
|
|
||||||
<frameset cols="25%,35%,45%">
|
|
||||||
<frame src="fr_file_index.html" title="Files" name="Files" />
|
|
||||||
<frame src="fr_class_index.html" name="Classes" />
|
|
||||||
<frame src="fr_method_index.html" name="Methods" />
|
|
||||||
</frameset>
|
|
||||||
<frame src="files/README.html" name="docwin" />
|
|
||||||
</frameset>
|
|
||||||
</html>
|
|
||||||
@@ -1,208 +0,0 @@
|
|||||||
|
|
||||||
body {
|
|
||||||
font-family: Verdana,Arial,Helvetica,sans-serif;
|
|
||||||
font-size: 90%;
|
|
||||||
margin: 0;
|
|
||||||
margin-left: 40px;
|
|
||||||
padding: 0;
|
|
||||||
background: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
|
|
||||||
h1 { font-size: 150%; }
|
|
||||||
h2,h3,h4 { margin-top: 1em; }
|
|
||||||
|
|
||||||
a { background: #eef; color: #039; text-decoration: none; }
|
|
||||||
a:hover { background: #039; color: #eef; }
|
|
||||||
|
|
||||||
/* Override the base stylesheet's Anchor inside a table cell */
|
|
||||||
td > a {
|
|
||||||
background: transparent;
|
|
||||||
color: #039;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* and inside a section title */
|
|
||||||
.section-title > a {
|
|
||||||
background: transparent;
|
|
||||||
color: #eee;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* === Structural elements =================================== */
|
|
||||||
|
|
||||||
div#index {
|
|
||||||
margin: 0;
|
|
||||||
margin-left: -40px;
|
|
||||||
padding: 0;
|
|
||||||
font-size: 90%;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
div#index a {
|
|
||||||
margin-left: 0.7em;
|
|
||||||
}
|
|
||||||
|
|
||||||
div#index .section-bar {
|
|
||||||
margin-left: 0px;
|
|
||||||
padding-left: 0.7em;
|
|
||||||
background: #ccc;
|
|
||||||
font-size: small;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
div#classHeader, div#fileHeader {
|
|
||||||
width: auto;
|
|
||||||
color: white;
|
|
||||||
padding: 0.5em 1.5em 0.5em 1.5em;
|
|
||||||
margin: 0;
|
|
||||||
margin-left: -40px;
|
|
||||||
border-bottom: 3px solid #006;
|
|
||||||
}
|
|
||||||
|
|
||||||
div#classHeader a, div#fileHeader a {
|
|
||||||
background: inherit;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
div#classHeader td, div#fileHeader td {
|
|
||||||
background: inherit;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
div#fileHeader {
|
|
||||||
background: #057;
|
|
||||||
}
|
|
||||||
|
|
||||||
div#classHeader {
|
|
||||||
background: #048;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.class-name-in-header {
|
|
||||||
font-size: 180%;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
div#bodyContent {
|
|
||||||
padding: 0 1.5em 0 1.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
div#description {
|
|
||||||
padding: 0.5em 1.5em;
|
|
||||||
background: #efefef;
|
|
||||||
border: 1px dotted #999;
|
|
||||||
}
|
|
||||||
|
|
||||||
div#description h1,h2,h3,h4,h5,h6 {
|
|
||||||
color: #125;;
|
|
||||||
background: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
div#validator-badges {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
div#validator-badges img { border: 0; }
|
|
||||||
|
|
||||||
div#copyright {
|
|
||||||
color: #333;
|
|
||||||
background: #efefef;
|
|
||||||
font: 0.75em sans-serif;
|
|
||||||
margin-top: 5em;
|
|
||||||
margin-bottom: 0;
|
|
||||||
padding: 0.5em 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* === Classes =================================== */
|
|
||||||
|
|
||||||
table.header-table {
|
|
||||||
color: white;
|
|
||||||
font-size: small;
|
|
||||||
}
|
|
||||||
|
|
||||||
.type-note {
|
|
||||||
font-size: small;
|
|
||||||
color: #DEDEDE;
|
|
||||||
}
|
|
||||||
|
|
||||||
.xxsection-bar {
|
|
||||||
background: #eee;
|
|
||||||
color: #333;
|
|
||||||
padding: 3px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.section-bar {
|
|
||||||
color: #333;
|
|
||||||
border-bottom: 1px solid #999;
|
|
||||||
margin-left: -20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.section-title {
|
|
||||||
background: #79a;
|
|
||||||
color: #eee;
|
|
||||||
padding: 3px;
|
|
||||||
margin-top: 2em;
|
|
||||||
margin-left: -30px;
|
|
||||||
border: 1px solid #999;
|
|
||||||
}
|
|
||||||
|
|
||||||
.top-aligned-row { vertical-align: top }
|
|
||||||
.bottom-aligned-row { vertical-align: bottom }
|
|
||||||
|
|
||||||
/* --- Context section classes ----------------------- */
|
|
||||||
|
|
||||||
.context-row { }
|
|
||||||
.context-item-name { font-family: monospace; font-weight: bold; color: black; }
|
|
||||||
.context-item-value { font-size: small; color: #448; }
|
|
||||||
.context-item-desc { color: #333; padding-left: 2em; }
|
|
||||||
|
|
||||||
/* --- Method classes -------------------------- */
|
|
||||||
.method-detail {
|
|
||||||
background: #efefef;
|
|
||||||
padding: 0;
|
|
||||||
margin-top: 0.5em;
|
|
||||||
margin-bottom: 1em;
|
|
||||||
border: 1px dotted #ccc;
|
|
||||||
}
|
|
||||||
.method-heading {
|
|
||||||
color: black;
|
|
||||||
background: #ccc;
|
|
||||||
border-bottom: 1px solid #666;
|
|
||||||
padding: 0.2em 0.5em 0 0.5em;
|
|
||||||
}
|
|
||||||
.method-signature { color: black; background: inherit; }
|
|
||||||
.method-name { font-weight: bold; }
|
|
||||||
.method-args { font-style: italic; }
|
|
||||||
.method-description { padding: 0 0.5em 0 0.5em; }
|
|
||||||
|
|
||||||
/* --- Source code sections -------------------- */
|
|
||||||
|
|
||||||
a.source-toggle { font-size: 90%; }
|
|
||||||
div.method-source-code {
|
|
||||||
background: #262626;
|
|
||||||
color: #ffdead;
|
|
||||||
margin: 1em;
|
|
||||||
padding: 0.5em;
|
|
||||||
border: 1px dashed #999;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
div.method-source-code pre { color: #ffdead; overflow: hidden; }
|
|
||||||
|
|
||||||
/* --- Ruby keyword styles --------------------- */
|
|
||||||
|
|
||||||
.standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
|
|
||||||
|
|
||||||
.ruby-constant { color: #7fffd4; background: transparent; }
|
|
||||||
.ruby-keyword { color: #00ffff; background: transparent; }
|
|
||||||
.ruby-ivar { color: #eedd82; background: transparent; }
|
|
||||||
.ruby-operator { color: #00ffee; background: transparent; }
|
|
||||||
.ruby-identifier { color: #ffdead; background: transparent; }
|
|
||||||
.ruby-node { color: #ffa07a; background: transparent; }
|
|
||||||
.ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
|
|
||||||
.ruby-regexp { color: #ffa07a; background: transparent; }
|
|
||||||
.ruby-value { color: #7fffd4; background: transparent; }
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
# Copyright (c) 2005-2006 David Barri
|
|
||||||
|
|
||||||
module GLoc
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
CONFIG= {} unless const_defined?(:CONFIG)
|
|
||||||
unless CONFIG.frozen?
|
|
||||||
CONFIG[:default_language] ||= :en
|
|
||||||
CONFIG[:default_param_name] ||= 'lang'
|
|
||||||
CONFIG[:default_cookie_name] ||= 'lang'
|
|
||||||
CONFIG[:raise_string_not_found_errors]= true unless CONFIG.has_key?(:raise_string_not_found_errors)
|
|
||||||
CONFIG[:verbose] ||= false
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
# Copyright (c) 2005-2006 David Barri
|
|
||||||
|
|
||||||
require 'date'
|
|
||||||
|
|
||||||
module ActionView #:nodoc:
|
|
||||||
module Helpers #:nodoc:
|
|
||||||
module DateHelper
|
|
||||||
|
|
||||||
unless const_defined?(:LOCALIZED_HELPERS)
|
|
||||||
LOCALIZED_HELPERS= true
|
|
||||||
LOCALIZED_MONTHNAMES = {}
|
|
||||||
LOCALIZED_ABBR_MONTHNAMES = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
# This method uses <tt>current_language</tt> to return a localized string.
|
|
||||||
def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
|
|
||||||
from_time = from_time.to_time if from_time.respond_to?(:to_time)
|
|
||||||
to_time = to_time.to_time if to_time.respond_to?(:to_time)
|
|
||||||
distance_in_minutes = (((to_time - from_time).abs)/60).round
|
|
||||||
distance_in_seconds = ((to_time - from_time).abs).round
|
|
||||||
|
|
||||||
case distance_in_minutes
|
|
||||||
when 0..1
|
|
||||||
return (distance_in_minutes==0) ? l(:actionview_datehelper_time_in_words_minute_less_than) : l(:actionview_datehelper_time_in_words_minute_single) unless include_seconds
|
|
||||||
case distance_in_seconds
|
|
||||||
when 0..5 then lwr(:actionview_datehelper_time_in_words_second_less_than, 5)
|
|
||||||
when 6..10 then lwr(:actionview_datehelper_time_in_words_second_less_than, 10)
|
|
||||||
when 11..20 then lwr(:actionview_datehelper_time_in_words_second_less_than, 20)
|
|
||||||
when 21..40 then l(:actionview_datehelper_time_in_words_minute_half)
|
|
||||||
when 41..59 then l(:actionview_datehelper_time_in_words_minute_less_than)
|
|
||||||
else l(:actionview_datehelper_time_in_words_minute)
|
|
||||||
end
|
|
||||||
|
|
||||||
when 2..45 then lwr(:actionview_datehelper_time_in_words_minute, distance_in_minutes)
|
|
||||||
when 46..90 then l(:actionview_datehelper_time_in_words_hour_about_single)
|
|
||||||
when 90..1440 then lwr(:actionview_datehelper_time_in_words_hour_about, (distance_in_minutes.to_f / 60.0).round)
|
|
||||||
when 1441..2880 then lwr(:actionview_datehelper_time_in_words_day, 1)
|
|
||||||
else lwr(:actionview_datehelper_time_in_words_day, (distance_in_minutes / 1440).round)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# This method has been modified so that a localized string can be appended to the day numbers.
|
|
||||||
def select_day(date, options = {})
|
|
||||||
day_options = []
|
|
||||||
prefix = l :actionview_datehelper_select_day_prefix
|
|
||||||
|
|
||||||
1.upto(31) do |day|
|
|
||||||
day_options << ((date && (date.kind_of?(Fixnum) ? date : date.day) == day) ?
|
|
||||||
%(<option value="#{day}" selected="selected">#{day}#{prefix}</option>\n) :
|
|
||||||
%(<option value="#{day}">#{day}#{prefix}</option>\n)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
select_html(options[:field_name] || 'day', day_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled])
|
|
||||||
end
|
|
||||||
|
|
||||||
# This method has been modified so that
|
|
||||||
# * the month names are localized.
|
|
||||||
# * it uses options: <tt>:min_date</tt>, <tt>:max_date</tt>, <tt>:start_month</tt>, <tt>:end_month</tt>
|
|
||||||
# * a localized string can be appended to the month numbers when the <tt>:use_month_numbers</tt> option is specified.
|
|
||||||
def select_month(date, options = {})
|
|
||||||
unless LOCALIZED_MONTHNAMES.has_key?(current_language)
|
|
||||||
LOCALIZED_MONTHNAMES[current_language] = [''] + l(:actionview_datehelper_select_month_names).split(',')
|
|
||||||
LOCALIZED_ABBR_MONTHNAMES[current_language] = [''] + l(:actionview_datehelper_select_month_names_abbr).split(',')
|
|
||||||
end
|
|
||||||
|
|
||||||
month_options = []
|
|
||||||
month_names = options[:use_short_month] ? LOCALIZED_ABBR_MONTHNAMES[current_language] : LOCALIZED_MONTHNAMES[current_language]
|
|
||||||
|
|
||||||
if options.has_key?(:min_date) && options.has_key?(:max_date)
|
|
||||||
if options[:min_date].year == options[:max_date].year
|
|
||||||
start_month, end_month = options[:min_date].month, options[:max_date].month
|
|
||||||
end
|
|
||||||
end
|
|
||||||
start_month = (options[:start_month] || 1) unless start_month
|
|
||||||
end_month = (options[:end_month] || 12) unless end_month
|
|
||||||
prefix = l :actionview_datehelper_select_month_prefix
|
|
||||||
|
|
||||||
start_month.upto(end_month) do |month_number|
|
|
||||||
month_name = if options[:use_month_numbers]
|
|
||||||
"#{month_number}#{prefix}"
|
|
||||||
elsif options[:add_month_numbers]
|
|
||||||
month_number.to_s + ' - ' + month_names[month_number]
|
|
||||||
else
|
|
||||||
month_names[month_number]
|
|
||||||
end
|
|
||||||
|
|
||||||
month_options << ((date && (date.kind_of?(Fixnum) ? date : date.month) == month_number) ?
|
|
||||||
%(<option value="#{month_number}" selected="selected">#{month_name}</option>\n) :
|
|
||||||
%(<option value="#{month_number}">#{month_name}</option>\n)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
select_html(options[:field_name] || 'month', month_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled])
|
|
||||||
end
|
|
||||||
|
|
||||||
# This method has been modified so that
|
|
||||||
# * it uses options: <tt>:min_date</tt>, <tt>:max_date</tt>
|
|
||||||
# * a localized string can be appended to the years numbers.
|
|
||||||
def select_year(date, options = {})
|
|
||||||
year_options = []
|
|
||||||
y = date ? (date.kind_of?(Fixnum) ? (y = (date == 0) ? Date.today.year : date) : date.year) : Date.today.year
|
|
||||||
|
|
||||||
start_year = options.has_key?(:min_date) ? options[:min_date].year : (options[:start_year] || y-5)
|
|
||||||
end_year = options.has_key?(:max_date) ? options[:max_date].year : (options[:end_year] || y+5)
|
|
||||||
step_val = start_year < end_year ? 1 : -1
|
|
||||||
prefix = l :actionview_datehelper_select_year_prefix
|
|
||||||
|
|
||||||
start_year.step(end_year, step_val) do |year|
|
|
||||||
year_options << ((date && (date.kind_of?(Fixnum) ? date : date.year) == year) ?
|
|
||||||
%(<option value="#{year}" selected="selected">#{year}#{prefix}</option>\n) :
|
|
||||||
%(<option value="#{year}">#{year}#{prefix}</option>\n)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
select_html(options[:field_name] || 'year', year_options, options[:prefix], options[:include_blank], options[:discard_type], options[:disabled])
|
|
||||||
end
|
|
||||||
|
|
||||||
# added by JP Lang
|
|
||||||
# select_html is a rails private method and changed in 1.2
|
|
||||||
# implementation added here for compatibility
|
|
||||||
def select_html(type, options, prefix = nil, include_blank = false, discard_type = false, disabled = false)
|
|
||||||
select_html = %(<select name="#{prefix || "date"})
|
|
||||||
select_html << "[#{type}]" unless discard_type
|
|
||||||
select_html << %(")
|
|
||||||
select_html << %( disabled="disabled") if disabled
|
|
||||||
select_html << %(>\n)
|
|
||||||
select_html << %(<option value=""></option>\n) if include_blank
|
|
||||||
select_html << options.to_s
|
|
||||||
select_html << "</select>\n"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# The private method <tt>add_options</tt> is overridden so that "Please select" is localized.
|
|
||||||
class InstanceTag
|
|
||||||
private
|
|
||||||
|
|
||||||
def add_options(option_tags, options, value = nil)
|
|
||||||
option_tags = "<option value=\"\"></option>\n" + option_tags if options[:include_blank]
|
|
||||||
|
|
||||||
if value.blank? && options[:prompt]
|
|
||||||
("<option value=\"\">#{options[:prompt].kind_of?(String) ? options[:prompt] : l(:actionview_instancetag_blank_option)}</option>\n") + option_tags
|
|
||||||
else
|
|
||||||
option_tags
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
namespace :gloc do
|
|
||||||
desc 'Sorts the keys in the lang ymls'
|
|
||||||
task :sort do
|
|
||||||
dir = ENV['DIR'] || '{.,vendor/plugins/*}/lang'
|
|
||||||
puts "Processing directory #{dir}"
|
|
||||||
files = Dir.glob(File.join(dir,'*.{yaml,yml}'))
|
|
||||||
puts 'No files found.' if files.empty?
|
|
||||||
files.each {|file|
|
|
||||||
puts "Sorting file: #{file}"
|
|
||||||
header = []
|
|
||||||
content = IO.readlines(file)
|
|
||||||
content.each {|line| line.gsub!(/[\s\r\n\t]+$/,'')}
|
|
||||||
content.delete_if {|line| line==''}
|
|
||||||
tmp= []
|
|
||||||
content.each {|x| tmp << x unless tmp.include?(x)}
|
|
||||||
content= tmp
|
|
||||||
header << content.shift if !content.empty? && content[0] =~ /^file_charset:/
|
|
||||||
content.sort!
|
|
||||||
filebak = "#{file}.bak"
|
|
||||||
File.rename file, filebak
|
|
||||||
File.open(file, 'w') {|fout| fout << header.join("\n") << content.join("\n") << "\n"}
|
|
||||||
File.delete filebak
|
|
||||||
# Report duplicates
|
|
||||||
count= {}
|
|
||||||
content.map {|x| x.gsub(/:.+$/, '') }.each {|x| count[x] ||= 0; count[x] += 1}
|
|
||||||
count.delete_if {|k,v|v==1}
|
|
||||||
puts count.keys.sort.map{|x|" WARNING: Duplicate key '#{x}' (#{count[x]} occurances)"}.join("\n") unless count.empty?
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Updates language files based on em.yml content'
|
|
||||||
task :update do
|
|
||||||
dir = ENV['DIR'] || './lang'
|
|
||||||
|
|
||||||
en_strings = {}
|
|
||||||
en_file = File.open(File.join(dir,'en.yml'), 'r')
|
|
||||||
en_file.each_line {|line| en_strings[$1] = $2 if line =~ %r{^([\w_]+):\s(.+)$} }
|
|
||||||
en_file.close
|
|
||||||
|
|
||||||
files = Dir.glob(File.join(dir,'*.{yaml,yml}'))
|
|
||||||
files.each do |file|
|
|
||||||
puts "Updating file #{file}"
|
|
||||||
keys = IO.readlines(file).collect {|line| $1 if line =~ %r{^([\w_]+):\s(.+)$} }.compact
|
|
||||||
lang = File.open(file, 'a')
|
|
||||||
en_strings.each do |key, str|
|
|
||||||
next if keys.include?(key)
|
|
||||||
puts "added: #{key}"
|
|
||||||
lang << "#{key}: #{str}\n"
|
|
||||||
end
|
|
||||||
lang.close
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
in_both_langs: This is in en+ja
|
|
||||||
en_only: English only
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
in_both_langs: enにもjaにもある
|
|
||||||
ja_only: 日本語のみ
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
en_only: overriden dude
|
|
||||||
new_en: This is a new English string
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
in_both_langs: 更新された
|
|
||||||
new_ja: 新たな日本語ストリング
|
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
== Version 1.2 (11 Feb 2007)
|
||||||
|
|
||||||
|
* Added language select-tag functions
|
||||||
|
* Localized values can now be CustomTypes.
|
||||||
|
* Localized values can now be basic ruby types (true/false, Fixnum, Symbol, Array, Hash)
|
||||||
|
* Localized values can now be procs, lambdas.
|
||||||
|
* Added a custom type called 'sameas' which can be used to make a value the same as another.
|
||||||
|
* Fixed bug in ActiveRecord::Errors.add
|
||||||
|
* Added methods: l_without_args, ll_without_args, ltry_without_args
|
||||||
|
* date_select and datetime_select now use a default :order param (d/m/y) which is specified in lang files
|
||||||
|
* Added a yesno_radio_buttons() method for views.
|
||||||
|
* Date/time formats no longer need double percentage signs. (%%d/%%m -> %d/%m)
|
||||||
|
* Removed l_datetime_short().
|
||||||
|
* Added French strings. (Thanks to François Billard-Madrières)
|
||||||
|
* Date/time functions now localize the weekday/month names.
|
||||||
|
* Updated to work with Rails v1.2.1
|
||||||
|
* All internal constants moved out of the GLoc module so they are no longer inherited.
|
||||||
|
* Added two modes of get/set current_language functionality. In simple mode (which is the new default) the current_language setting is global. In cascading mode (the previous default) the current_language can be configured at instance, class and global levels. What this means is that you will now no longer need to manually set the language of models after already setting the language in the controller (unless running in the old cascading mode).
|
||||||
|
* autodetect_language_filter now parses HTTP_ACCEPT_LANGUAGE correctly and takes language weights into consideration.
|
||||||
|
|
||||||
|
== Version 1.1 (28 May 2006)
|
||||||
|
|
||||||
|
* The charset for each and/or all languages can now be easily configured.
|
||||||
|
* Added a ActionController filter that auto-detects the client language.
|
||||||
|
* The rake task "sort" now merges lines that match 100%, and warns if duplicate keys are found.
|
||||||
|
* Rule support. Create flexible rules to handle issues such as pluralization.
|
||||||
|
* Massive speed and stability improvements to development mode.
|
||||||
|
* Added Russian strings. (Thanks to Evgeny Lineytsev)
|
||||||
|
* Complete RDoc documentation.
|
||||||
|
* Improved helpers.
|
||||||
|
* GLoc now configurable via get_config and set_config
|
||||||
|
* Added an option to tell GLoc to output various verbose information.
|
||||||
|
* More useful functions such as set_language_if_valid, similar_language
|
||||||
|
* GLoc's entire internal state can now be backed up and restored.
|
||||||
|
|
||||||
|
|
||||||
|
== Version 1.0 (17 April 2006)
|
||||||
|
|
||||||
|
* Initial public release.
|
||||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2005-2006 David Barri
|
Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
+52
-15
@@ -33,6 +33,19 @@ NOTE: This is not complete. Timezones and countries are not currently localized.
|
|||||||
|
|
||||||
= Usage
|
= Usage
|
||||||
|
|
||||||
|
=== Installation
|
||||||
|
You have two options.
|
||||||
|
|
||||||
|
1) Simply download and extract to vendor/plugins/gloc.
|
||||||
|
|
||||||
|
2) Use script/plugin.
|
||||||
|
To install GLoc v.1.2.0 type:
|
||||||
|
ruby script/plugin install svn://rubyforge.org/var/svn/gloc/tags/gloc-1_2_0
|
||||||
|
|
||||||
|
To install the latest version of GLoc from the trunk type:
|
||||||
|
ruby script/plugin install svn://rubyforge.org/var/svn/gloc/trunk
|
||||||
|
|
||||||
|
|
||||||
=== Quickstart
|
=== Quickstart
|
||||||
|
|
||||||
Windows users will need to first install iconv. http://wiki.rubyonrails.com/rails/pages/iconv
|
Windows users will need to first install iconv. http://wiki.rubyonrails.com/rails/pages/iconv
|
||||||
@@ -42,26 +55,34 @@ Windows users will need to first install iconv. http://wiki.rubyonrails.com/rail
|
|||||||
* Put the following in config/environment.rb and change the values as you see fit. The following example is for an app that uses English and Japanese, with Japanese being the default.
|
* Put the following in config/environment.rb and change the values as you see fit. The following example is for an app that uses English and Japanese, with Japanese being the default.
|
||||||
GLoc.set_config :default_language => :ja
|
GLoc.set_config :default_language => :ja
|
||||||
GLoc.clear_strings_except :en, :ja
|
GLoc.clear_strings_except :en, :ja
|
||||||
GLoc.set_kcode
|
|
||||||
GLoc.load_localized_strings
|
GLoc.load_localized_strings
|
||||||
* Add 'include GLoc' to all classes that will use localization. This is added to most Rails classes automatically.
|
* Add 'include GLoc' to all classes that will use localization. This is added to most Rails classes automatically.
|
||||||
* Optionally, you can set the language for models and controllers by simply inserting <tt>set_language :en</tt> in classes and/or methods.
|
* Optionally, you can set the language for models and controllers by simply inserting <tt>set_language :en</tt> in classes and/or methods.
|
||||||
* To use localized strings, replace text such as <tt>"Welcome"</tt> with <tt>l(:welcome_string_key)</tt>, and <tt>"Hello #{name}."</tt> with <tt>l(:hello_string_key, name)</tt>. (Of course the strings will need to exist in your string bundle.)
|
* To use localized strings, replace text such as <tt>"Welcome"</tt> with <tt>l(:welcome_string_key)</tt>, and <tt>"Hello #{name}."</tt> with <tt>l(:hello_string_key, name)</tt>. (Of course the strings will need to exist in your string bundle.)
|
||||||
|
|
||||||
There is more functionality provided by this plugin, that is not demonstrated above. Please read the API summary for details.
|
There is more functionality provided by GLoc, that is not demonstrated above. Please see the sample GLoc application and/or read the API summary for details.
|
||||||
|
|
||||||
|
=== Sample GLoc Application
|
||||||
|
|
||||||
|
A sample GLoc application that demos most GLoc functionality is available and is a GREAT place to look for help. After all, we're all programmers so why read a description of how GLoc works when instead you can see it in action and in a simple, easy-to-understand environment.
|
||||||
|
Check it out here:
|
||||||
|
svn://rubyforge.org/var/svn/gloc/supp/sample_rails_app
|
||||||
|
|
||||||
=== API summary
|
=== API summary
|
||||||
|
|
||||||
The following methods are added as both class methods and instance methods to modules/classes that include GLoc. They are also available as class methods of GLoc.
|
The following methods are added as both class methods and instance methods to modules/classes that include GLoc. They are also available as class methods of GLoc.
|
||||||
current_language # Returns the current language
|
current_language # Returns the current language
|
||||||
l(symbol, *arguments) # Returns a localized string
|
l(symbol, *arguments) # Returns a localized string
|
||||||
ll(lang, symbol, *arguments) # Returns a localized string in a specific language
|
l_without_args(symbol) # Returns a raw localized value without applying arguments to it.
|
||||||
ltry(possible_key) # Returns a localized string if passed a Symbol, else returns the same argument passed
|
ll(lang, symbol, *arguments) # Returns a localized string in a specific language
|
||||||
lwr(symbol, *arguments) # Uses the default rule to return a localized string.
|
ll_without_args(lang, symbol) # Returns a raw localized value in a specified language without applying arguments to it.
|
||||||
lwr_(rule, symbol, *arguments) # Uses a specified rule to return a localized string.
|
ltry(possible_key) # Returns a localized string if passed a Symbol, else returns the same argument passed
|
||||||
l_has_string?(symbol) # Checks if a localized string exists
|
ltry_without_args(possible_key) # If the argument is a symbol, this returns a raw localized value without applying arguments to it. Else it just returns the argument.
|
||||||
set_language(language) # Sets the language for the current class or class instance
|
lwr(symbol, *arguments) # Uses the default rule to return a localized string.
|
||||||
set_language_if_valid(lang) # Sets the current language if the language passed is a valid language
|
lwr_(rule, symbol, *arguments) # Uses a specified rule to return a localized string.
|
||||||
|
l_has_string?(symbol) # Checks if a localized string exists
|
||||||
|
set_language(language) # Sets the language for the current class or class instance
|
||||||
|
set_language_if_valid(lang) # Sets the current language if the language passed is a valid language
|
||||||
|
|
||||||
The GLoc module also defines the following class methods:
|
The GLoc module also defines the following class methods:
|
||||||
add_localized_strings(lang, symbol_hash, override=true) # Adds a hash of localized strings
|
add_localized_strings(lang, symbol_hash, override=true) # Adds a hash of localized strings
|
||||||
@@ -74,6 +95,7 @@ The GLoc module also defines the following class methods:
|
|||||||
restore_state(state) # Restores a backup of GLoc's internal state
|
restore_state(state) # Restores a backup of GLoc's internal state
|
||||||
set_charset(new_charset, *langs) # Sets the charset used to internally store localized strings
|
set_charset(new_charset, *langs) # Sets the charset used to internally store localized strings
|
||||||
set_config(hash) # Sets GLoc configuration values (see below)
|
set_config(hash) # Sets GLoc configuration values (see below)
|
||||||
|
set_language_mode(mode) # Changes the way in which <tt>current_language</tt> and <tt>set_language</tt> work.
|
||||||
set_kcode(charset=nil) # Sets the $KCODE global variable
|
set_kcode(charset=nil) # Sets the $KCODE global variable
|
||||||
similar_language(language) # Tries to find a valid language that is similar to the argument passed
|
similar_language(language) # Tries to find a valid language that is similar to the argument passed
|
||||||
valid_languages # Returns an array of (currently) valid languages (ie. languages for which localized data exists)
|
valid_languages # Returns an array of (currently) valid languages (ie. languages for which localized data exists)
|
||||||
@@ -109,10 +131,26 @@ GLoc also makes the following change to Rails:
|
|||||||
* Instances of ActiveView inherit their current_language from the controller (or mailer) creating them.
|
* Instances of ActiveView inherit their current_language from the controller (or mailer) creating them.
|
||||||
|
|
||||||
This plugin also adds the following rake tasks:
|
This plugin also adds the following rake tasks:
|
||||||
* gloc:sort - Sorts the keys in the lang ymls (also accepts a DIR argument)
|
* gloc:sort # Sorts the keys in string bundles (also accepts a DIR argument)
|
||||||
|
* gloc:cmpkeys # Compares keys in different language string bundles
|
||||||
|
|
||||||
=== Cascading language configuration
|
=== Non-String Localication Values
|
||||||
|
|
||||||
|
When you are storing localized values you are no longer restricted to using strings.
|
||||||
|
You can use all sorts of ruby types such as numbers, hashs, arrays, procs, etc.
|
||||||
|
You can use a special !!sameas directive to make a value equal to another key.
|
||||||
|
For date/time formats you just need to specify !!datetime_fmt.
|
||||||
|
You can also create your own custom types (see gloc_custom_types.rb).
|
||||||
|
For more information please have a look at the sample GLoc application (see above).
|
||||||
|
|
||||||
|
=== Current-Language Mode
|
||||||
|
|
||||||
|
There are two modes of determining how the current_language setting works.
|
||||||
|
|
||||||
|
1) Simple. The default mode.
|
||||||
|
Setting the language once, anywhere effects all calls to current_language() in that process.
|
||||||
|
|
||||||
|
2) Cascading.
|
||||||
The language can be set at three levels:
|
The language can be set at three levels:
|
||||||
1. The default # GLoc.get_config :default_language
|
1. The default # GLoc.get_config :default_language
|
||||||
2. Class level # class A; set_language :de; end
|
2. Class level # class A; set_language :de; end
|
||||||
@@ -172,9 +210,8 @@ GLoc includes the following helpers:
|
|||||||
l_age(age) # Returns a localized version of an age. eg "3 years old"
|
l_age(age) # Returns a localized version of an age. eg "3 years old"
|
||||||
l_date(date) # Returns a date in a localized format
|
l_date(date) # Returns a date in a localized format
|
||||||
l_datetime(date) # Returns a date+time in a localized format
|
l_datetime(date) # Returns a date+time in a localized format
|
||||||
l_datetime_short(date) # Returns a date+time in a localized short format.
|
|
||||||
l_lang_name(l,dl=nil) # Returns the name of a language (you must supply your own strings)
|
l_lang_name(l,dl=nil) # Returns the name of a language (you must supply your own strings)
|
||||||
l_strftime(date,fmt) # Formats a date/time in a localized format.
|
l_strftime(fmt,date) # Formats a date/time in a localized format.
|
||||||
l_time(date) # Returns a time in a localized format
|
l_time(date) # Returns a time in a localized format
|
||||||
l_YesNo(value) # Returns localized string of "Yes" or "No" depending on the arg
|
l_YesNo(value) # Returns localized string of "Yes" or "No" depending on the arg
|
||||||
l_yesno(value) # Returns localized string of "yes" or "no" depending on the arg
|
l_yesno(value) # Returns localized string of "yes" or "no" depending on the arg
|
||||||
Vendored
+3
-2
@@ -8,8 +8,9 @@ Rake::RDocTask.new() { |rdoc|
|
|||||||
rdoc.rdoc_dir = 'doc'
|
rdoc.rdoc_dir = 'doc'
|
||||||
rdoc.title = "GLoc Localization Library Documentation"
|
rdoc.title = "GLoc Localization Library Documentation"
|
||||||
rdoc.options << '--line-numbers' << '--inline-source'
|
rdoc.options << '--line-numbers' << '--inline-source'
|
||||||
rdoc.rdoc_files.include('README', 'CHANGELOG')
|
rdoc.rdoc_files.include('README', 'CHANGELOG', *Dir.glob('UPGRADING*.txt'))
|
||||||
rdoc.rdoc_files.include('lib/**/*.rb')
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
||||||
rdoc.rdoc_files.exclude('lib/gloc-dev.rb')
|
rdoc.rdoc_files.exclude('lib/gloc-dev.rb')
|
||||||
rdoc.rdoc_files.exclude('lib/gloc-config.rb')
|
rdoc.rdoc_files.exclude('lib/gloc-internal.rb')
|
||||||
|
rdoc.rdoc_files.exclude('lib/gloc-custom_types.rb')
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
This file is mainly intended for users of GLoc v1.1.
|
||||||
|
For a full list of changes see the CHANGELOG file and believe me, there are MANY a
|
||||||
|
cool, new feature there!!
|
||||||
|
|
||||||
|
== API changes between GLoc 1.1 and GLoc 1.2
|
||||||
|
|
||||||
|
* l_strftime has had it argument ordcer reversed. It is now l_strftime(fmt,date)
|
||||||
|
instead of l_strftime(date,fmt)
|
||||||
|
|
||||||
|
* l_datetime_short() has been removed. Feel free to add as many date/time formats as you
|
||||||
|
like though. Use the new !!datetime_fmt directive. (See the sample app)
|
||||||
|
|
||||||
|
* Date/time formats no longer require double hash-symbols. ie. '%%A' is now just '%A'.
|
||||||
|
|
||||||
|
* Some localized strings used for Rails date/time helpers have been changed.
|
||||||
|
actionview_datehelper_select_*_prefix
|
||||||
|
has been renamed to
|
||||||
|
actionview_datehelper_select_*_suffix
|
||||||
|
|
||||||
|
|
||||||
|
== Design change
|
||||||
|
When I first created GLoc, I designed it so that language settings cascaded. So
|
||||||
|
you could have a global language setting, and you could set a certain controller
|
||||||
|
to have another certain language setting, and then setting the language in
|
||||||
|
instances of that controller would only effect that instance, etc etc. First of all,
|
||||||
|
not only did I find myself never actually needing that behaviour, but other users
|
||||||
|
also found it confusing. Many users would set the language in the controller and then
|
||||||
|
not understand why they would also need to explictly set the language of model instances
|
||||||
|
before running validation methods. Well this behaviour has been replaced by a simpler,
|
||||||
|
one-language-per-process model. In simple mode (which is now the default), there is only
|
||||||
|
one language setting and it is shared by all instances and classes. This means you will
|
||||||
|
now only need to call set_language() once-per-action.
|
||||||
|
If you want to enable the old cascading behaviour, you still can by calling
|
||||||
|
GLoc.set_language_mode(:cascading)
|
||||||
|
|
||||||
|
|
||||||
|
== Sample GLoc Application
|
||||||
|
|
||||||
|
To see the new functionality in action, it's best just to have a look at the new sample application.
|
||||||
|
Specially for the new stuff like !!datetime_fmt and !!sameas
|
||||||
|
Check it out here:
|
||||||
|
svn://rubyforge.org/var/svn/gloc/supp/sample_rails_app
|
||||||
Vendored
+2
-2
@@ -1,11 +1,11 @@
|
|||||||
# Copyright (c) 2005-2006 David Barri
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
require 'gloc'
|
require 'gloc'
|
||||||
require 'gloc-ruby'
|
require 'gloc-ruby'
|
||||||
require 'gloc-rails'
|
require 'gloc-rails'
|
||||||
require 'gloc-rails-text'
|
require 'gloc-rails-text'
|
||||||
require 'gloc-config'
|
|
||||||
|
|
||||||
require 'gloc-dev' if ENV['RAILS_ENV'] == 'development'
|
require 'gloc-dev' if ENV['RAILS_ENV'] == 'development'
|
||||||
|
|
||||||
|
GLoc.set_language_mode :simple
|
||||||
GLoc.load_gloc_default_localized_strings
|
GLoc.load_gloc_default_localized_strings
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
|
require 'yaml'
|
||||||
|
|
||||||
|
module GLoc
|
||||||
|
module Constants
|
||||||
|
UTF_8= 'utf-8'
|
||||||
|
SHIFT_JIS= 'sjis'
|
||||||
|
EUC_JP= 'euc-jp'
|
||||||
|
|
||||||
|
CONFIG= {
|
||||||
|
:default_language => :en,
|
||||||
|
:default_param_name => 'lang',
|
||||||
|
:default_cookie_name => 'lang',
|
||||||
|
:raise_string_not_found_errors => true,
|
||||||
|
:verbose => false,
|
||||||
|
}
|
||||||
|
|
||||||
|
LOCALIZED_STRINGS= {}
|
||||||
|
LOWERCASE_LANGUAGES= {}
|
||||||
|
RULES= {}
|
||||||
|
YAML_PRIVATETYPE2= YAML::Syck::PrivateType rescue YAML::PrivateType unless const_defined?(:YAML_PRIVATETYPE2)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
|
module GLoc
|
||||||
|
class CustomType
|
||||||
|
include ::GLoc::Constants
|
||||||
|
|
||||||
|
def self.is_valid_type?(type)
|
||||||
|
[:array, :datetime_fmt, :hash, :lambda, :proc, :sameas].include? type
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(lang,type,value,charset)
|
||||||
|
@lang= lang
|
||||||
|
@type= type.to_sym
|
||||||
|
raise UnsupportedValueTypeError.new("Unsupported value type: '#{@type}'") unless self.class.is_valid_type?(@type)
|
||||||
|
[:set_value].each {|m|
|
||||||
|
instance_eval "alias :#{m} :#{@type}_#{m}"
|
||||||
|
}
|
||||||
|
[:set_charset, :value_with_args].each {|m|
|
||||||
|
m2= :"#{@type}_#{m}"
|
||||||
|
instance_eval "alias :#{m} :#{m2}" if respond_to?(m2)
|
||||||
|
}
|
||||||
|
@original_value= value
|
||||||
|
@original_charset= charset
|
||||||
|
set_value value
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_charset(new_charset)
|
||||||
|
set_value Iconv.iconv(new_charset, @original_charset, @original_value)[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
def value
|
||||||
|
@value
|
||||||
|
end
|
||||||
|
|
||||||
|
def value_with_args(*args)
|
||||||
|
raise InvalidArgumentsError.new("The custom type '#{@type}' does not accept arguments.") unless args.empty?
|
||||||
|
@value
|
||||||
|
end
|
||||||
|
|
||||||
|
#===========================================================================
|
||||||
|
# Array
|
||||||
|
|
||||||
|
def array_set_charset(charset)
|
||||||
|
Iconv.open(charset, @original_charset) {|iconv|
|
||||||
|
array_set_value2 @original_value, iconv, charset
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def array_set_value(a)
|
||||||
|
array_set_value2 a, nil, nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def array_set_value2(a, iconv, charset)
|
||||||
|
@value= []
|
||||||
|
a.each_index {|i|
|
||||||
|
@value[i]= GLoc._internalize_value(a[i], @lang, @original_charset)
|
||||||
|
@value[i]= GLoc._set_value_charset(@value[i], iconv, charset) if iconv
|
||||||
|
@value[i]= @value[i].value_with_args() if @value[i].is_a?(CustomType)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
private :array_set_value2
|
||||||
|
|
||||||
|
#===========================================================================
|
||||||
|
# datetime_fmt
|
||||||
|
|
||||||
|
def datetime_fmt_set_value(v)
|
||||||
|
v2= v.gsub('%%',"\0")
|
||||||
|
subs= {
|
||||||
|
:a => v2.include?('%a'),
|
||||||
|
:A => v2.include?('%A'),
|
||||||
|
:b => v2.include?('%b'),
|
||||||
|
:B => v2.include?('%B'),
|
||||||
|
}
|
||||||
|
x= nil
|
||||||
|
if subs.values.include?(true)
|
||||||
|
x= "v= #{v2.inspect};"
|
||||||
|
x<< "v.gsub! '%a', GLoc.ll(@lang,:general_text_day_names_abbr )[d.wday];" if subs[:a]
|
||||||
|
x<< "v.gsub! '%A', GLoc.ll(@lang,:general_text_day_names )[d.wday];" if subs[:A]
|
||||||
|
x<< "v.gsub! '%b', GLoc.ll(@lang,:general_text_month_names_abbr)[d.month-1];" if subs[:b]
|
||||||
|
x<< "v.gsub! '%B', GLoc.ll(@lang,:general_text_month_names )[d.month-1];" if subs[:B]
|
||||||
|
x<< %[v.gsub! "\0", '%%';]
|
||||||
|
x<< 'd.strftime v'
|
||||||
|
else
|
||||||
|
x= "d.strftime #{v.inspect}"
|
||||||
|
end
|
||||||
|
@value= eval "lambda do |d| #{x} end"
|
||||||
|
end
|
||||||
|
|
||||||
|
def datetime_fmt_value_with_args(*args)
|
||||||
|
@value.call(*args)
|
||||||
|
end
|
||||||
|
|
||||||
|
#===========================================================================
|
||||||
|
# Hash
|
||||||
|
|
||||||
|
def hash_set_charset(charset)
|
||||||
|
Iconv.open(charset, @original_charset) {|iconv|
|
||||||
|
hash_set_value2 @original_value, iconv, charset
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def hash_set_value(h)
|
||||||
|
hash_set_value2 h, nil, nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def hash_set_value2(h, iconv, charset)
|
||||||
|
@value= {}
|
||||||
|
h.each {|k,v|
|
||||||
|
hash_set_value3 k, v, iconv, charset
|
||||||
|
sk= k.is_a?(String) ? (k.to_sym rescue nil) : nil
|
||||||
|
hash_set_value3 sk, v, iconv, charset if sk && !@value.has_key?(sk)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
def hash_set_value3(k, v, iconv, charset)
|
||||||
|
@value[k]= GLoc._internalize_value(v, @lang, @original_charset)
|
||||||
|
@value[k]= GLoc._set_value_charset(@value[k], iconv, charset) if iconv
|
||||||
|
@value[k]= @value[k].value_with_args() if @value[k].is_a?(CustomType)
|
||||||
|
end
|
||||||
|
private :hash_set_value2, :hash_set_value3
|
||||||
|
|
||||||
|
#===========================================================================
|
||||||
|
# Lambda
|
||||||
|
|
||||||
|
def lambda_set_charset(new_charset)
|
||||||
|
@iconv_for_output.close if @iconv_for_output
|
||||||
|
@iconv_for_output= (new_charset == UTF_8 ? nil : Iconv.new(new_charset,UTF_8))
|
||||||
|
end
|
||||||
|
|
||||||
|
def lambda_set_value(v)
|
||||||
|
lambda_set_value2 :lambda, 'lambda', v
|
||||||
|
end
|
||||||
|
|
||||||
|
def lambda_set_value2(type, lambda_creation, v)
|
||||||
|
send "#{type}_set_charset", @original_charset
|
||||||
|
v= Iconv.iconv(UTF_8,@original_charset,v)[0] unless @original_charset == UTF_8
|
||||||
|
@value= eval "#{lambda_creation} do #{v} end"
|
||||||
|
end
|
||||||
|
private :lambda_set_value2
|
||||||
|
|
||||||
|
def lambda_value_with_args(*args)
|
||||||
|
if @iconv_for_output
|
||||||
|
@iconv_for_output.iconv @value.call(*args)
|
||||||
|
else
|
||||||
|
@value.call(*args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#===========================================================================
|
||||||
|
# Proc
|
||||||
|
|
||||||
|
def proc_set_value(v)
|
||||||
|
lambda_set_value2 :proc, 'Proc.new', v
|
||||||
|
end
|
||||||
|
|
||||||
|
alias :proc_set_charset :lambda_set_charset
|
||||||
|
alias :proc_value_with_args :lambda_value_with_args
|
||||||
|
|
||||||
|
#===========================================================================
|
||||||
|
# sameas
|
||||||
|
|
||||||
|
def sameas_set_charset(charset)
|
||||||
|
end
|
||||||
|
|
||||||
|
def sameas_set_value(v)
|
||||||
|
@key= v.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def sameas_value_with_args(*args)
|
||||||
|
GLoc.ll(@lang,@key,*args)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2005-2006 David Barri
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
puts "GLoc v#{GLoc::VERSION} running in development mode. Strings can be modified at runtime."
|
puts "GLoc v#{GLoc::VERSION} running in development mode. Strings can be modified at runtime."
|
||||||
|
|
||||||
+5
-6
@@ -1,14 +1,13 @@
|
|||||||
# Copyright (c) 2005-2006 David Barri
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
module GLoc
|
module GLoc
|
||||||
# These helper methods will be included in the InstanceMethods module.
|
# These helper methods will be included in the InstanceMethods module.
|
||||||
module Helpers
|
module Helpers
|
||||||
def l_age(age) lwr :general_fmt_age, age end
|
def l_age(age) lwr :general_fmt_age, age end
|
||||||
def l_date(date) l_strftime date, :general_fmt_date end
|
def l_date(date) l_strftime :general_fmt_date, date end
|
||||||
def l_datetime(date) l_strftime date, :general_fmt_datetime end
|
def l_datetime(date) l_strftime :general_fmt_datetime, date end
|
||||||
def l_datetime_short(date) l_strftime date, :general_fmt_datetime_short end
|
def l_strftime(fmt,date) l(fmt,date) end
|
||||||
def l_strftime(date,fmt) date.strftime l(fmt) end
|
def l_time(time) l_strftime :general_fmt_time, time end
|
||||||
def l_time(time) l_strftime time, :general_fmt_time end
|
|
||||||
def l_YesNo(value) l(value ? :general_text_Yes : :general_text_No) end
|
def l_YesNo(value) l(value ? :general_text_Yes : :general_text_No) end
|
||||||
def l_yesno(value) l(value ? :general_text_yes : :general_text_no) end
|
def l_yesno(value) l(value ? :general_text_yes : :general_text_no) end
|
||||||
|
|
||||||
+60
-27
@@ -1,7 +1,9 @@
|
|||||||
# Copyright (c) 2005-2006 David Barri
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
require 'iconv'
|
require 'iconv'
|
||||||
require 'gloc-version'
|
require 'yaml'
|
||||||
|
require 'gloc-constants'
|
||||||
|
require 'gloc-custom_types'
|
||||||
|
|
||||||
module GLoc
|
module GLoc
|
||||||
class GLocError < StandardError #:nodoc:
|
class GLocError < StandardError #:nodoc:
|
||||||
@@ -14,8 +16,11 @@ module GLoc
|
|||||||
end
|
end
|
||||||
class StringNotFoundError < GLocError #:nodoc:
|
class StringNotFoundError < GLocError #:nodoc:
|
||||||
end
|
end
|
||||||
|
class UnsupportedValueTypeError < GLocError #:nodoc:
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
include ::GLoc::Constants
|
||||||
private
|
private
|
||||||
|
|
||||||
def _add_localized_data(lang, symbol_hash, override, target) #:nodoc:
|
def _add_localized_data(lang, symbol_hash, override, target) #:nodoc:
|
||||||
@@ -68,30 +73,59 @@ module GLoc
|
|||||||
set_charset UTF_8 unless CONFIG[:internal_charset]
|
set_charset UTF_8 unless CONFIG[:internal_charset]
|
||||||
end
|
end
|
||||||
|
|
||||||
def _get_internal_state_vars
|
def _get_internal_state_vars #:nodoc:
|
||||||
[ CONFIG, LOCALIZED_STRINGS, RULES, LOWERCASE_LANGUAGES ]
|
[ CONFIG, LOCALIZED_STRINGS, RULES, LOWERCASE_LANGUAGES ]
|
||||||
end
|
end
|
||||||
|
|
||||||
def _get_lang_file_list(dir) #:nodoc:
|
def _get_lang_file_list(dir) #:nodoc:
|
||||||
dir= File.join(RAILS_ROOT,'{.,vendor/plugins/*}','lang') if dir.nil?
|
dir= File.join(RAILS_ROOT,'lang') if dir.nil?
|
||||||
Dir[File.join(dir,'*.{yaml,yml}')]
|
Dir[File.join(dir,'*.{yaml,yml}')]
|
||||||
end
|
end
|
||||||
|
|
||||||
def _l(symbol, language, *arguments) #:nodoc:
|
def _internalize_value(value, lang, charset) #:nodoc:
|
||||||
symbol= symbol.to_sym if symbol.is_a?(String)
|
case value
|
||||||
raise InvalidKeyError.new("Symbol or String expected as key.") unless symbol.kind_of?(Symbol)
|
when YAML::PrivateType, YAML_PRIVATETYPE2
|
||||||
|
CustomType.new(lang, value.type_id, value.value, charset)
|
||||||
|
when Array
|
||||||
|
CustomType.new(lang, :array, value, charset)
|
||||||
|
when Hash
|
||||||
|
CustomType.new(lang, :hash, value, charset)
|
||||||
|
when nil
|
||||||
|
''
|
||||||
|
when String, Symbol, Fixnum, true, false
|
||||||
|
value
|
||||||
|
else
|
||||||
|
raise UnsupportedValueTypeError.new("Unsupported value type: #{value.class}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
translation= LOCALIZED_STRINGS[language][symbol] rescue nil
|
def _l(key, language, *arguments) #:nodoc:
|
||||||
if translation.nil?
|
translation= _l_without_args(key, language)
|
||||||
raise StringNotFoundError.new("There is no key called '#{symbol}' in the #{language} strings.") if CONFIG[:raise_string_not_found_errors]
|
case translation
|
||||||
translation= symbol.to_s
|
when String
|
||||||
|
begin
|
||||||
|
translation % arguments
|
||||||
|
rescue => e
|
||||||
|
raise InvalidArgumentsError.new("Translation value #{translation.inspect} with arguments #{arguments.inspect} caused error '#{e.message}'")
|
||||||
|
end
|
||||||
|
when CustomType
|
||||||
|
translation.value_with_args(*arguments)
|
||||||
|
else
|
||||||
|
translation
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def _l_without_args(key, language) #:nodoc:
|
||||||
|
key= key.to_sym if key.is_a?(String)
|
||||||
|
raise InvalidKeyError.new("Symbol or String expected as key.") unless key.kind_of?(Symbol)
|
||||||
|
|
||||||
|
translation= LOCALIZED_STRINGS[language][key] rescue nil
|
||||||
|
if translation.nil? && !_l_has_string?(key,language)
|
||||||
|
raise StringNotFoundError.new("There is no key called '#{key}' in the #{language} strings.") if CONFIG[:raise_string_not_found_errors]
|
||||||
|
translation= key.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
translation
|
||||||
return translation % arguments
|
|
||||||
rescue => e
|
|
||||||
raise InvalidArgumentsError.new("Translation value #{translation.inspect} with arguments #{arguments.inspect} caused error '#{e.message}'")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def _l_has_string?(symbol,lang) #:nodoc:
|
def _l_has_string?(symbol,lang) #:nodoc:
|
||||||
@@ -108,7 +142,15 @@ module GLoc
|
|||||||
r
|
r
|
||||||
end
|
end
|
||||||
|
|
||||||
def _verbose_msg(type=nil)
|
def _set_value_charset(v, iconv, charset) #:nodoc:
|
||||||
|
case v
|
||||||
|
when String then iconv.iconv(v)
|
||||||
|
when CustomType then v.set_charset(charset); v
|
||||||
|
else v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def _verbose_msg(type=nil) #:nodoc:
|
||||||
return unless CONFIG[:verbose]
|
return unless CONFIG[:verbose]
|
||||||
x= case type
|
x= case type
|
||||||
when :stats
|
when :stats
|
||||||
@@ -120,15 +162,6 @@ module GLoc
|
|||||||
puts "[GLoc] #{x}"
|
puts "[GLoc] #{x}"
|
||||||
end
|
end
|
||||||
|
|
||||||
public :_l, :_l_has_string?, :_l_rule
|
public :_l, :_l_has_string?, :_l_rule, :_l_without_args, :_internalize_value, :_set_value_charset
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
unless const_defined?(:LOCALIZED_STRINGS)
|
|
||||||
LOCALIZED_STRINGS= {}
|
|
||||||
RULES= {}
|
|
||||||
LOWERCASE_LANGUAGES= {}
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
|
module GLoc
|
||||||
|
class << self
|
||||||
|
# Changes the way in which <tt>current_language</tt> and <tt>set_language</tt> work.
|
||||||
|
# The available modes are <tt>:simple</tt> and <tt>:cascading</tt>.
|
||||||
|
#
|
||||||
|
# In simple mode, the current language setting is global (which is fine for 99% of all apps and situations).
|
||||||
|
#
|
||||||
|
# In cascading mode, everything that includes the GLoc module (instances, classes + modules) have their own
|
||||||
|
# language setting. The language is determined as such: instance -> class -> global setting. This was the
|
||||||
|
# way the GLoc worked up until v1.2.0.
|
||||||
|
def set_language_mode(mode)
|
||||||
|
case mode
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
when :simple
|
||||||
|
eval <<EOB
|
||||||
|
module ::GLoc
|
||||||
|
def current_language
|
||||||
|
GLoc::Constants::CONFIG[:default_language]
|
||||||
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def current_language
|
||||||
|
CONFIG[:default_language]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module InstanceMethods
|
||||||
|
def set_language(language)
|
||||||
|
GLoc::Constants::CONFIG[:default_language]= language.nil? ? nil : language.to_sym
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module ClassMethods
|
||||||
|
def current_language
|
||||||
|
GLoc::Constants::CONFIG[:default_language]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
EOB
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
when :cascading
|
||||||
|
eval <<EOB
|
||||||
|
module ::GLoc
|
||||||
|
def current_language
|
||||||
|
@gloc_language || self.class.current_language
|
||||||
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def current_language
|
||||||
|
CONFIG[:default_language]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module InstanceMethods
|
||||||
|
def set_language(language)
|
||||||
|
@gloc_language= language.nil? ? nil : language.to_sym
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module ClassMethods
|
||||||
|
def current_language
|
||||||
|
@gloc_language || GLoc.current_language
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
EOB
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
else
|
||||||
|
raise "Invalid mode."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end # class << self
|
||||||
|
end # module GLoc
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
|
require 'date'
|
||||||
|
|
||||||
|
module ActionView #:nodoc:
|
||||||
|
module Helpers #:nodoc:
|
||||||
|
module DateHelper
|
||||||
|
|
||||||
|
unless const_defined?(:LOCALIZED_HELPERS)
|
||||||
|
LOCALIZED_HELPERS= true
|
||||||
|
LOCALIZED_MONTHNAMES = {}
|
||||||
|
LOCALIZED_ABBR_MONTHNAMES = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
# This method uses <tt>current_language</tt> to return a localized string.
|
||||||
|
def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
|
||||||
|
from_time = from_time.to_time if from_time.respond_to?(:to_time)
|
||||||
|
to_time = to_time.to_time if to_time.respond_to?(:to_time)
|
||||||
|
distance_in_minutes = (((to_time - from_time).abs)/60).round
|
||||||
|
distance_in_seconds = ((to_time - from_time).abs).round
|
||||||
|
|
||||||
|
case distance_in_minutes
|
||||||
|
when 0..1
|
||||||
|
return (distance_in_minutes==0) ? l(:actionview_datehelper_time_in_words_minute_less_than) : l(:actionview_datehelper_time_in_words_minute_single) unless include_seconds
|
||||||
|
case distance_in_seconds
|
||||||
|
when 0..4 then lwr(:actionview_datehelper_time_in_words_second_less_than, 5)
|
||||||
|
when 5..9 then lwr(:actionview_datehelper_time_in_words_second_less_than, 10)
|
||||||
|
when 10..19 then lwr(:actionview_datehelper_time_in_words_second_less_than, 20)
|
||||||
|
when 20..39 then l(:actionview_datehelper_time_in_words_minute_half)
|
||||||
|
when 40..59 then l(:actionview_datehelper_time_in_words_minute_less_than)
|
||||||
|
else l(:actionview_datehelper_time_in_words_minute_single)
|
||||||
|
end
|
||||||
|
|
||||||
|
when 2..44 then lwr(:actionview_datehelper_time_in_words_minute, distance_in_minutes)
|
||||||
|
when 45..89 then l(:actionview_datehelper_time_in_words_hour_about_single)
|
||||||
|
when 90..1439 then lwr(:actionview_datehelper_time_in_words_hour_about, (distance_in_minutes.to_f / 60.0).round)
|
||||||
|
when 1440..2879 then lwr(:actionview_datehelper_time_in_words_day, 1)
|
||||||
|
when 2880..43199 then lwr(:actionview_datehelper_time_in_words_day, (distance_in_minutes / 1440).round)
|
||||||
|
when 43200..86399 then l(:actionview_datehelper_time_in_words_month_about)
|
||||||
|
when 86400..525959 then lwr(:actionview_datehelper_time_in_words_month,(distance_in_minutes / 43200).round)
|
||||||
|
when 525960..1051919 then l(:actionview_datehelper_time_in_words_year_about)
|
||||||
|
else lwr(:actionview_datehelper_time_in_words_year_over,(distance_in_minutes / 525960).round)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# The order of d/m/y depends on the language (unless already specified in the options hash).
|
||||||
|
def date_select_with_gloc(object_name, method, options = {})
|
||||||
|
options[:order] ||= l(:actionview_datehelper_date_select_order)
|
||||||
|
date_select_without_gloc(object_name, method, options)
|
||||||
|
end
|
||||||
|
alias_method_chain :date_select, :gloc
|
||||||
|
|
||||||
|
# The order of d/m/y depends on the language (unless already specified in the options hash).
|
||||||
|
def datetime_select_with_gloc(object_name, method, options = {})
|
||||||
|
options[:order] ||= l(:actionview_datehelper_date_select_order)
|
||||||
|
datetime_select_without_gloc(object_name, method, options)
|
||||||
|
end
|
||||||
|
alias_method_chain :datetime_select, :gloc
|
||||||
|
|
||||||
|
# This method has been modified so that a localized string can be appended to the day numbers.
|
||||||
|
def select_day(date, options = {})
|
||||||
|
if options[:use_hidden]
|
||||||
|
val = date ? (date.kind_of?(Fixnum) ? date : date.day) : ''
|
||||||
|
hidden_html(options[:field_name] || 'day', val, options)
|
||||||
|
else
|
||||||
|
day_options = []
|
||||||
|
suffix = l :actionview_datehelper_select_day_suffix
|
||||||
|
|
||||||
|
if options.has_key?(:min_date) && options.has_key?(:max_date)
|
||||||
|
if options[:min_date].year == options[:max_date].year && options[:min_date].month == options[:max_date].month
|
||||||
|
start_day, end_day = options[:min_date].day, options[:max_date].day
|
||||||
|
end
|
||||||
|
end
|
||||||
|
start_day ||= 1
|
||||||
|
end_day ||= 31
|
||||||
|
|
||||||
|
start_day.upto(end_day) do |day|
|
||||||
|
day_options << ((date && (date.kind_of?(Fixnum) ? date : date.day) == day) ?
|
||||||
|
%(<option value="#{day}" selected="selected">#{day}#{suffix}</option>\n) :
|
||||||
|
%(<option value="#{day}">#{day}#{suffix}</option>\n)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
select_html(options[:field_name] || 'day', day_options, options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# This method has been modified so that
|
||||||
|
# * the month names are localized.
|
||||||
|
# * it uses options: <tt>:min_date</tt>, <tt>:max_date</tt>, <tt>:start_month</tt>, <tt>:end_month</tt>
|
||||||
|
# * a localized string can be appended to the month numbers when the <tt>:use_month_numbers</tt> option is specified.
|
||||||
|
def select_month(date, options = {})
|
||||||
|
if options[:use_hidden]
|
||||||
|
val = date ? (date.kind_of?(Fixnum) ? date : date.month) : ''
|
||||||
|
hidden_html(options[:field_name] || 'month', val, options)
|
||||||
|
else
|
||||||
|
|
||||||
|
unless LOCALIZED_MONTHNAMES.has_key?(current_language)
|
||||||
|
LOCALIZED_MONTHNAMES[current_language] = [''] + l(:general_text_month_names)
|
||||||
|
LOCALIZED_ABBR_MONTHNAMES[current_language] = [''] + l(:general_text_month_names_abbr)
|
||||||
|
end
|
||||||
|
|
||||||
|
month_options = []
|
||||||
|
month_names = options[:use_short_month] ? LOCALIZED_ABBR_MONTHNAMES[current_language] : LOCALIZED_MONTHNAMES[current_language]
|
||||||
|
|
||||||
|
if options.has_key?(:min_date) && options.has_key?(:max_date)
|
||||||
|
if options[:min_date].year == options[:max_date].year
|
||||||
|
start_month, end_month = options[:min_date].month, options[:max_date].month
|
||||||
|
end
|
||||||
|
end
|
||||||
|
start_month ||= (options[:start_month] || 1)
|
||||||
|
end_month ||= (options[:end_month] || 12)
|
||||||
|
suffix = l :actionview_datehelper_select_month_suffix
|
||||||
|
|
||||||
|
start_month.upto(end_month) do |month_number|
|
||||||
|
month_name = if options[:use_month_numbers]
|
||||||
|
"#{month_number}#{suffix}"
|
||||||
|
elsif options[:add_month_numbers]
|
||||||
|
month_number.to_s + ' - ' + month_names[month_number]
|
||||||
|
else
|
||||||
|
month_names[month_number]
|
||||||
|
end
|
||||||
|
|
||||||
|
month_options << ((date && (date.kind_of?(Fixnum) ? date : date.month) == month_number) ?
|
||||||
|
%(<option value="#{month_number}" selected="selected">#{month_name}</option>\n) :
|
||||||
|
%(<option value="#{month_number}">#{month_name}</option>\n)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
select_html(options[:field_name] || 'month', month_options, options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# This method has been modified so that
|
||||||
|
# * it uses options: <tt>:min_date</tt>, <tt>:max_date</tt>
|
||||||
|
# * a localized string can be appended to the years numbers.
|
||||||
|
def select_year(date, options = {})
|
||||||
|
if options[:use_hidden]
|
||||||
|
val = date ? (date.kind_of?(Fixnum) ? date : date.year) : ''
|
||||||
|
hidden_html(options[:field_name] || 'year', val, options)
|
||||||
|
else
|
||||||
|
year_options = []
|
||||||
|
y = date ? (date.kind_of?(Fixnum) ? (y = (date == 0) ? Date.today.year : date) : date.year) : Date.today.year
|
||||||
|
|
||||||
|
start_year = options.has_key?(:min_date) ? options[:min_date].year : (options[:start_year] || y-5)
|
||||||
|
end_year = options.has_key?(:max_date) ? options[:max_date].year : (options[:end_year] || y+5)
|
||||||
|
step_val = start_year < end_year ? 1 : -1
|
||||||
|
suffix = l :actionview_datehelper_select_year_suffix
|
||||||
|
|
||||||
|
start_year.step(end_year, step_val) do |year|
|
||||||
|
year_options << ((date && (date.kind_of?(Fixnum) ? date : date.year) == year) ?
|
||||||
|
%(<option value="#{year}" selected="selected">#{year}#{suffix}</option>\n) :
|
||||||
|
%(<option value="#{year}">#{year}#{suffix}</option>\n)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
select_html(options[:field_name] || 'year', year_options, options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end # module DateHelper
|
||||||
|
|
||||||
|
# The private method <tt>add_options</tt> is overridden so that "Please select" is localized.
|
||||||
|
class InstanceTag
|
||||||
|
private
|
||||||
|
def add_options(option_tags, options, value = nil)
|
||||||
|
option_tags = "<option value=\"\"></option>\n" + option_tags if options[:include_blank]
|
||||||
|
if value.blank? && options[:prompt]
|
||||||
|
("<option value=\"\">#{options[:prompt].kind_of?(String) ? options[:prompt] : l(:actionview_instancetag_blank_option)}</option>\n") + option_tags
|
||||||
|
else
|
||||||
|
option_tags
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end # class InstanceTag
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
+76
-47
@@ -1,10 +1,33 @@
|
|||||||
# Copyright (c) 2005-2006 David Barri
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
require 'gloc'
|
require 'gloc'
|
||||||
|
|
||||||
module ActionController #:nodoc:
|
module ActionController #:nodoc:
|
||||||
class Base #:nodoc:
|
class Base #:nodoc:
|
||||||
include GLoc
|
include GLoc
|
||||||
|
|
||||||
|
# Returns a valid language that best suits the HTTP_ACCEPT_LANGUAGE request header.
|
||||||
|
# If no valid language can be deduced, then <tt>nil</tt> is returned.
|
||||||
|
def get_valid_lang_from_accept_header
|
||||||
|
accept_langs= request.env['HTTP_ACCEPT_LANGUAGE'].split(/,/) rescue nil
|
||||||
|
return nil unless accept_langs
|
||||||
|
# Extract langs and sort by weight
|
||||||
|
# Example HTTP_ACCEPT_LANGUAGE: "en-au,en-gb;q=0.8,en;q=0.5,ja;q=0.3"
|
||||||
|
wl= {}
|
||||||
|
accept_langs.each {|accept_lang|
|
||||||
|
if (accept_lang + ';q=1') =~ /^(.+?);q=([^;]+).*/
|
||||||
|
wl[($2.to_f rescue -1.0)]= $1
|
||||||
|
end
|
||||||
|
}
|
||||||
|
sorted_langs= wl.sort{|a,b|b[0]<=>a[0]}.map{|a|a[1]}
|
||||||
|
# Look for an exact match
|
||||||
|
sorted_langs.each{|l| return l if GLoc.valid_language?(l)}
|
||||||
|
# Look for a similar match
|
||||||
|
ret= nil
|
||||||
|
sorted_langs.each{|l| ret ||= GLoc.similar_language(l)}
|
||||||
|
ret
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
module Filters #:nodoc:
|
module Filters #:nodoc:
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
@@ -55,11 +78,7 @@ module ActionController #:nodoc:
|
|||||||
end
|
end
|
||||||
# :check_accept_header
|
# :check_accept_header
|
||||||
unless options.delete(:check_accept_header) == false
|
unless options.delete(:check_accept_header) == false
|
||||||
x << %<
|
x << "l ||= c.get_valid_lang_from_accept_header;"
|
||||||
unless l
|
|
||||||
a= c.request.env['HTTP_ACCEPT_LANGUAGE'].split(/,|;/) rescue nil
|
|
||||||
a.each {|x| l ||= GLoc.similar_language(x)} if a
|
|
||||||
end; >
|
|
||||||
end
|
end
|
||||||
# Set language
|
# Set language
|
||||||
x << 'ret= true;'
|
x << 'ret= true;'
|
||||||
@@ -92,8 +111,7 @@ module ActionMailer #:nodoc:
|
|||||||
private
|
private
|
||||||
alias :render_message_without_gloc :render_message
|
alias :render_message_without_gloc :render_message
|
||||||
def render_message(method_name, body)
|
def render_message(method_name, body)
|
||||||
template = File.exist?("#{template_path}/#{method_name}_#{current_language}.rhtml") ? "#{method_name}_#{current_language}" : "#{method_name}"
|
render_message_without_gloc("#{method_name}_#{current_language}", body)
|
||||||
render_message_without_gloc(template, body)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -111,6 +129,34 @@ module ActionView #:nodoc:
|
|||||||
initialize_without_gloc(base_path, assigns_for_first_render, controller)
|
initialize_without_gloc(base_path, assigns_for_first_render, controller)
|
||||||
set_language controller.current_language unless controller.nil?
|
set_language controller.current_language unless controller.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Calls <tt>select</tt> and uses the current list of valid languages as the select options.
|
||||||
|
def select_lang(object, method, options= {}, html_options= {})
|
||||||
|
select object, method, select_lang_choices, options, html_options
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns an array of choices for <tt>select</tt> or <tt>options_for_select</tt> that consist of
|
||||||
|
# the current list of valid languages.
|
||||||
|
def select_lang_choices
|
||||||
|
GLoc.valid_languages.map{|l| [l_lang_name(l),l.to_s]}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Calls <tt>select_tag</tt> and uses the current list of valid languages as the select options.
|
||||||
|
def select_lang_tag(name, selected=nil, options= {})
|
||||||
|
select_tag name, options_for_select(select_lang_choices, selected), options
|
||||||
|
end
|
||||||
|
|
||||||
|
# Dispalys two radio buttons; one for yes and one for no.
|
||||||
|
# Accepts the following options:
|
||||||
|
# <tt>:gap</tt> -- specify the text to put between the yes/no options. For example '<br/>' would put the yes/no options on different lines. (Default is 3 spaces)
|
||||||
|
# <tt>:no_first</tt> -- Puts the 'no' radio button first. (Default is 'yes' first)
|
||||||
|
def yesno_radio_buttons(object, method, options={})
|
||||||
|
options= {:no_first => false, :gap => ' '}.merge(options)
|
||||||
|
y= "#{radio_button object, method, '1'} #{l_YesNo true}"
|
||||||
|
n= "#{radio_button object, method, '0'} #{l_YesNo false}"
|
||||||
|
options[:no_first] ? n+options[:gap]+y : y+options[:gap]+n
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Helpers #:nodoc:
|
module Helpers #:nodoc:
|
||||||
@@ -131,48 +177,31 @@ module ActiveRecord #:nodoc:
|
|||||||
include GLoc
|
include GLoc
|
||||||
end
|
end
|
||||||
|
|
||||||
# class Errors
|
|
||||||
# include GLoc
|
|
||||||
# alias :add_without_gloc :add
|
|
||||||
# # The GLoc version of this method provides two extra features
|
|
||||||
# # * If <tt>msg</tt> is a string, it will be considered a GLoc string key.
|
|
||||||
# # * If <tt>msg</tt> is an array, the first element will be considered
|
|
||||||
# # the string and the remaining elements will be considered arguments for the
|
|
||||||
# # string. Eg. <tt>['Hi %s.','John']</tt>
|
|
||||||
# def add(attribute, msg= @@default_error_messages[:invalid])
|
|
||||||
# if msg.is_a?(Array)
|
|
||||||
# args= msg.clone
|
|
||||||
# msg= args.shift
|
|
||||||
# args= nil if args.empty?
|
|
||||||
# end
|
|
||||||
# msg= ltry(msg)
|
|
||||||
# msg= msg % args unless args.nil?
|
|
||||||
# add_without_gloc(attribute, msg)
|
|
||||||
# end
|
|
||||||
# # Inherits the current language from the base record.
|
|
||||||
# def current_language
|
|
||||||
# @base.current_language
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
class Errors
|
class Errors
|
||||||
include GLoc
|
include GLoc
|
||||||
|
alias :add_without_gloc :add
|
||||||
def full_messages
|
# The GLoc version of this method provides two extra features
|
||||||
full_messages = []
|
# * If <tt>msg</tt> is a symbol, it will be considered a GLoc string key.
|
||||||
|
# * If <tt>msg</tt> is an array, the first element will be considered
|
||||||
@errors.each_key do |attr|
|
# the string and the remaining elements will be considered arguments for the
|
||||||
@errors[attr].each do |msg|
|
# string. Eg. <tt>['Hi %s.','John']</tt>
|
||||||
next if msg.nil?
|
def add(attribute, msg= @@default_error_messages[:invalid])
|
||||||
|
args= nil
|
||||||
if attr == "base"
|
if msg.is_a?(Array)
|
||||||
full_messages << (msg.is_a?(Symbol) ? l(msg) : msg)
|
args= msg.clone
|
||||||
else
|
msg= args.shift
|
||||||
full_messages << @base.class.human_attribute_name(attr) + " " + (msg.is_a?(Symbol) ? l(msg) : msg)
|
args= nil if args.empty?
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
full_messages
|
if msg.is_a?(Symbol)
|
||||||
|
msg= args ? l(msg,*args) : l(msg)
|
||||||
|
else
|
||||||
|
msg= msg % args if args
|
||||||
|
end
|
||||||
|
add_without_gloc(attribute, msg)
|
||||||
|
end
|
||||||
|
# Inherits the current language from the base record.
|
||||||
|
def current_language
|
||||||
|
@base.current_language
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2005-2006 David Barri
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
module Test # :nodoc:
|
module Test # :nodoc:
|
||||||
module Unit # :nodoc:
|
module Unit # :nodoc:
|
||||||
+5
-3
@@ -1,12 +1,14 @@
|
|||||||
|
require 'gloc-internal'
|
||||||
|
|
||||||
module GLoc
|
module GLoc
|
||||||
module VERSION #:nodoc:
|
module VERSION #:nodoc:
|
||||||
MAJOR = 1
|
MAJOR = 1
|
||||||
MINOR = 1
|
MINOR = 2
|
||||||
TINY = nil
|
TINY = nil
|
||||||
|
|
||||||
STRING= [MAJOR, MINOR, TINY].delete_if{|x|x.nil?}.join('.')
|
STRING= [MAJOR, MINOR, TINY].delete_if{|x|x.nil?}.join('.')
|
||||||
def self.to_s; STRING end
|
def self.to_s; STRING end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
puts "NOTICE: You are using a dev version of GLoc." if GLoc::VERSION::TINY == 'DEV'
|
_verbose_msg {"NOTICE: You are using a dev version of GLoc."} if GLoc::VERSION::TINY == 'DEV'
|
||||||
|
end
|
||||||
Vendored
+30
-31
@@ -1,14 +1,12 @@
|
|||||||
# Copyright (c) 2005-2006 David Barri
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'gloc-internal'
|
require 'gloc-internal'
|
||||||
require 'gloc-helpers'
|
require 'gloc-helpers'
|
||||||
|
require 'gloc-modes'
|
||||||
|
require 'gloc-version'
|
||||||
|
|
||||||
module GLoc
|
module GLoc
|
||||||
UTF_8= 'utf-8'
|
|
||||||
SHIFT_JIS= 'sjis'
|
|
||||||
EUC_JP= 'euc-jp'
|
|
||||||
|
|
||||||
# This module will be included in both instances and classes of GLoc includees.
|
# This module will be included in both instances and classes of GLoc includees.
|
||||||
# It is also included as class methods in the GLoc module itself.
|
# It is also included as class methods in the GLoc module itself.
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
@@ -19,17 +17,34 @@ module GLoc
|
|||||||
return GLoc._l(symbol,current_language,*arguments)
|
return GLoc._l(symbol,current_language,*arguments)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a raw localized value without applying arguments to it.
|
||||||
|
def l_without_args(symbol)
|
||||||
|
return GLoc._l_without_args(symbol,current_language)
|
||||||
|
end
|
||||||
|
|
||||||
# Returns a localized string in a specified language.
|
# Returns a localized string in a specified language.
|
||||||
# This does not effect <tt>current_language</tt>.
|
# This does not effect <tt>current_language</tt>.
|
||||||
def ll(lang, symbol, *arguments)
|
def ll(lang, symbol, *arguments)
|
||||||
return GLoc._l(symbol,lang.to_sym,*arguments)
|
return GLoc._l(symbol,lang.to_sym,*arguments)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a raw localized value in a specified language without applying arguments to it.
|
||||||
|
# This does not effect <tt>current_language</tt>.
|
||||||
|
def ll_without_args(lang, symbol)
|
||||||
|
return GLoc._l_without_args(symbol,lang.to_sym)
|
||||||
|
end
|
||||||
|
|
||||||
# Returns a localized string if the argument is a Symbol, else just returns the argument.
|
# Returns a localized string if the argument is a Symbol, else just returns the argument.
|
||||||
def ltry(possible_key)
|
def ltry(possible_key)
|
||||||
possible_key.is_a?(Symbol) ? l(possible_key) : possible_key
|
possible_key.is_a?(Symbol) ? l(possible_key) : possible_key
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# If the argument is a symbol, this returns a raw localized value without applying arguments to it.
|
||||||
|
# Else it just returns the argument.
|
||||||
|
def ltry_without_args(possible_key)
|
||||||
|
possible_key.is_a?(Symbol) ? l_without_args(possible_key) : possible_key
|
||||||
|
end
|
||||||
|
|
||||||
# Uses the default GLoc rule to return a localized string.
|
# Uses the default GLoc rule to return a localized string.
|
||||||
# See lwr_() for more info.
|
# See lwr_() for more info.
|
||||||
def lwr(symbol, *arguments)
|
def lwr(symbol, *arguments)
|
||||||
@@ -49,12 +64,6 @@ module GLoc
|
|||||||
return GLoc._l_has_string?(symbol,current_language)
|
return GLoc._l_has_string?(symbol,current_language)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets the current language for this instance/class.
|
|
||||||
# Setting the language of a class effects all instances unless the instance has its own language defined.
|
|
||||||
def set_language(language)
|
|
||||||
@gloc_language= language.nil? ? nil : language.to_sym
|
|
||||||
end
|
|
||||||
|
|
||||||
# Sets the current language if the language passed is a valid language.
|
# Sets the current language if the language passed is a valid language.
|
||||||
# If the language was valid, this method returns <tt>true</tt> else it will return <tt>false</tt>.
|
# If the language was valid, this method returns <tt>true</tt> else it will return <tt>false</tt>.
|
||||||
# Note that <tt>nil</tt> is not a valid language.
|
# Note that <tt>nil</tt> is not a valid language.
|
||||||
@@ -73,10 +82,6 @@ module GLoc
|
|||||||
# Instance
|
# Instance
|
||||||
|
|
||||||
include ::GLoc::InstanceMethods
|
include ::GLoc::InstanceMethods
|
||||||
# Returns the instance-level current language, or if not set, returns the class-level current language.
|
|
||||||
def current_language
|
|
||||||
@gloc_language || self.class.current_language
|
|
||||||
end
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# Class
|
# Class
|
||||||
@@ -85,10 +90,6 @@ module GLoc
|
|||||||
# Notice that the GLoc::InstanceMethods module is also included.
|
# Notice that the GLoc::InstanceMethods module is also included.
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
include ::GLoc::InstanceMethods
|
include ::GLoc::InstanceMethods
|
||||||
# Returns the current language, or if not set, returns the GLoc current language.
|
|
||||||
def current_language
|
|
||||||
@gloc_language || GLoc.current_language
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.included(target) #:nodoc:
|
def self.included(target) #:nodoc:
|
||||||
@@ -102,13 +103,9 @@ module GLoc
|
|||||||
# GLoc module
|
# GLoc module
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
include ::GLoc::Constants
|
||||||
include ::GLoc::InstanceMethods
|
include ::GLoc::InstanceMethods
|
||||||
|
|
||||||
# Returns the default language
|
|
||||||
def current_language
|
|
||||||
GLoc::CONFIG[:default_language]
|
|
||||||
end
|
|
||||||
|
|
||||||
# Adds a collection of localized strings to the in-memory string store.
|
# Adds a collection of localized strings to the in-memory string store.
|
||||||
def add_localized_strings(lang, symbol_hash, override=true, strings_charset=nil)
|
def add_localized_strings(lang, symbol_hash, override=true, strings_charset=nil)
|
||||||
_verbose_msg {"Adding #{symbol_hash.size} #{lang} strings."}
|
_verbose_msg {"Adding #{symbol_hash.size} #{lang} strings."}
|
||||||
@@ -169,19 +166,19 @@ module GLoc
|
|||||||
_get_lang_file_list(dir).each {|filename|
|
_get_lang_file_list(dir).each {|filename|
|
||||||
|
|
||||||
# Load file
|
# Load file
|
||||||
raw_hash = YAML::load(File.read(filename))
|
raw_hash= YAML::load(File.read(filename))
|
||||||
raw_hash={} unless raw_hash.kind_of?(Hash)
|
raw_hash= {} unless raw_hash.kind_of?(Hash)
|
||||||
filename =~ /([^\/\\]+)\.ya?ml$/
|
filename =~ /([^\/\\]+)\.ya?ml$/
|
||||||
lang = $1.to_sym
|
lang= $1.to_sym
|
||||||
file_charset = raw_hash['file_charset'] || UTF_8
|
file_charset= raw_hash['file_charset'] || UTF_8
|
||||||
|
|
||||||
# Convert string keys to symbols
|
# Pre-process file data
|
||||||
dest_charset= get_charset(lang)
|
dest_charset= get_charset(lang)
|
||||||
_verbose_msg {"Reading file #{filename} [charset: #{file_charset} --> #{dest_charset}]"}
|
_verbose_msg {"Reading file #{filename} [charset: #{file_charset} --> #{dest_charset}]"}
|
||||||
symbol_hash = {}
|
symbol_hash = {}
|
||||||
Iconv.open(dest_charset, file_charset) do |i|
|
Iconv.open(dest_charset, file_charset) do |i|
|
||||||
raw_hash.each {|key, value|
|
raw_hash.each {|key, value|
|
||||||
symbol_hash[key.to_sym] = i.iconv(value)
|
symbol_hash[key.to_sym]= _set_value_charset(_internalize_value(value, lang, file_charset), i, dest_charset)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -222,7 +219,9 @@ module GLoc
|
|||||||
_verbose_msg {"Converting :#{lang} strings from #{cur_charset} to #{new_charset}"}
|
_verbose_msg {"Converting :#{lang} strings from #{cur_charset} to #{new_charset}"}
|
||||||
Iconv.open(new_charset, cur_charset) do |i|
|
Iconv.open(new_charset, cur_charset) do |i|
|
||||||
bundle= LOCALIZED_STRINGS[lang]
|
bundle= LOCALIZED_STRINGS[lang]
|
||||||
bundle.each_pair {|k,v| bundle[k]= i.iconv(v)}
|
bundle.each_pair {|k,v|
|
||||||
|
bundle[k]= _set_value_charset(v, i, new_charset)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
namespace :gloc do
|
||||||
|
|
||||||
|
desc 'Sorts the keys in the string bundles'
|
||||||
|
task :sort do
|
||||||
|
dir = ENV['DIR'] || '{.,vendor/plugins/*}/lang'
|
||||||
|
puts "Processing directory #{dir}"
|
||||||
|
files = Dir.glob(File.join(dir,'*.{yaml,yml}'))
|
||||||
|
puts 'No files found.' if files.empty?
|
||||||
|
files.each {|file|
|
||||||
|
puts "Sorting file: #{file}"
|
||||||
|
header = []
|
||||||
|
content = IO.readlines(file)
|
||||||
|
content.each {|line| line.gsub!(/[\s\r\n\t]+$/,'')}
|
||||||
|
content.delete_if {|line| line==''}
|
||||||
|
tmp= []
|
||||||
|
content.each {|x| tmp << x unless tmp.include?(x)}
|
||||||
|
content= tmp
|
||||||
|
header << content.shift if !content.empty? && content[0] =~ /^file_charset:/
|
||||||
|
content.sort!
|
||||||
|
filebak = "#{file}.bak"
|
||||||
|
File.rename file, filebak
|
||||||
|
File.open(file, 'w') {|fout| fout << header.join("\n") << content.join("\n") << "\n"}
|
||||||
|
File.delete filebak
|
||||||
|
# Report duplicates
|
||||||
|
count= {}
|
||||||
|
content.map {|x| x.gsub(/:.+$/, '') }.each {|x| count[x] ||= 0; count[x] += 1}
|
||||||
|
count.delete_if {|k,v|v==1}
|
||||||
|
puts count.keys.sort.map{|x|" WARNING: Duplicate key '#{x}' (#{count[x]} occurances)"}.join("\n") unless count.empty?
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Compares the keys in different language string bundles'
|
||||||
|
task :cmpkeys do
|
||||||
|
dir= ENV['DIR'] || 'lang'
|
||||||
|
files= Dir.glob(File.join(dir,'*.{yaml,yml}'))
|
||||||
|
puts 'No files found.' if files.empty?
|
||||||
|
# Get data
|
||||||
|
keys= {}
|
||||||
|
langs= []
|
||||||
|
files.each {|file|
|
||||||
|
lang= File.basename(File.basename(file,'.yml'),'.yaml')
|
||||||
|
langs << lang
|
||||||
|
content= IO.readlines(file)
|
||||||
|
content.delete_if{|l| l.gsub!(%r{^\s+|\s+$},''); l==''}
|
||||||
|
content.map{|l| %r{^([^ :]+):} =~ l ? $1 : l}.each {|k|
|
||||||
|
keys[k] ||= {}
|
||||||
|
keys[k][lang]= true
|
||||||
|
}
|
||||||
|
puts "Loaded #{file} (#{content.size})"
|
||||||
|
}
|
||||||
|
total_string_count= keys.size
|
||||||
|
# Remove keys where all match
|
||||||
|
keys.delete_if {|k,v| v.size == langs.size}
|
||||||
|
# Display results
|
||||||
|
langs.sort!
|
||||||
|
x= '+' + langs.map{|l| '-' + '-'*l.length + '-+' }.join('')
|
||||||
|
puts x
|
||||||
|
puts '+' + langs.map{|l| ' ' + l + ' +'}.join('')
|
||||||
|
puts x
|
||||||
|
keys.keys.sort.each {|k|
|
||||||
|
v= keys[k]
|
||||||
|
puts '| ' + langs.map{|l| (v[l] ? '*' : ' ') + ' '*l.length}.join('| ') + '| ' + k
|
||||||
|
}
|
||||||
|
puts x
|
||||||
|
langs.each {|l|
|
||||||
|
c= 0
|
||||||
|
keys.each_pair{|k,v| c += 1 unless v[l] }
|
||||||
|
puts "Bundle :#{l} is missing #{c} strings of #{total_string_count}"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2005-2006 David Barri
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
$LOAD_PATH.push File.join(File.dirname(__FILE__),'..','lib')
|
$LOAD_PATH.push File.join(File.dirname(__FILE__),'..','lib')
|
||||||
require "#{File.dirname(__FILE__)}/../../../../test/test_helper"
|
require "#{File.dirname(__FILE__)}/../../../../test/test_helper"
|
||||||
+224
-8
@@ -1,12 +1,28 @@
|
|||||||
# Copyright (c) 2005-2006 David Barri
|
# Copyright (c) 2005-2007 David Barri
|
||||||
|
|
||||||
$LOAD_PATH.push File.join(File.dirname(__FILE__),'..','lib')
|
$LOAD_PATH.push File.join(File.dirname(__FILE__),'..','lib')
|
||||||
require 'gloc'
|
require 'gloc'
|
||||||
require 'gloc-ruby'
|
require 'gloc-ruby'
|
||||||
require 'gloc-config'
|
GLoc.set_language_mode :cascading
|
||||||
require 'gloc-rails-text'
|
GLoc.set_kcode
|
||||||
require File.join(File.dirname(__FILE__),'lib','rails-time_ext') unless 3.respond_to?(:days)
|
require File.join(File.dirname(__FILE__),'lib','rails-time_ext') unless 3.respond_to?(:days)
|
||||||
require File.join(File.dirname(__FILE__),'lib','rails-string_ext') unless ''.respond_to?(:starts_with?)
|
require File.join(File.dirname(__FILE__),'lib','rails-string_ext') unless ''.respond_to?(:starts_with?)
|
||||||
|
|
||||||
|
class Module
|
||||||
|
def alias_method_chain(target, feature)
|
||||||
|
# Strip out punctuation on predicates or bang methods since
|
||||||
|
# e.g. target?_without_feature is not a valid method name.
|
||||||
|
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
||||||
|
yield(aliased_target, punctuation) if block_given?
|
||||||
|
alias_method "#{aliased_target}_without_#{feature}#{punctuation}", target
|
||||||
|
alias_method target, "#{aliased_target}_with_#{feature}#{punctuation}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
module ActionView; module Helpers; module DateHelper
|
||||||
|
def date_select(object_name, method, options={}) end
|
||||||
|
def datetime_select(object_name, method, options={}) end
|
||||||
|
end end end
|
||||||
|
require 'gloc-rails-text'
|
||||||
#require 'gloc-dev'
|
#require 'gloc-dev'
|
||||||
|
|
||||||
class LClass; include GLoc; end
|
class LClass; include GLoc; end
|
||||||
@@ -27,7 +43,7 @@ class GLocTest < Test::Unit::TestCase
|
|||||||
@l2.set_language :en
|
@l2.set_language :en
|
||||||
@l3.set_language 'en_AU'
|
@l3.set_language 'en_AU'
|
||||||
@gloc_state= GLoc.backup_state true
|
@gloc_state= GLoc.backup_state true
|
||||||
GLoc::CONFIG.merge!({
|
GLoc::Constants::CONFIG.merge!({
|
||||||
:default_param_name => 'lang',
|
:default_param_name => 'lang',
|
||||||
:default_cookie_name => 'lang',
|
:default_cookie_name => 'lang',
|
||||||
:default_language => :ja,
|
:default_language => :ja,
|
||||||
@@ -269,7 +285,6 @@ class GLocTest < Test::Unit::TestCase
|
|||||||
0.upto(120) {|n| l_age(n)}
|
0.upto(120) {|n| l_age(n)}
|
||||||
l_date(t)
|
l_date(t)
|
||||||
l_datetime(t)
|
l_datetime(t)
|
||||||
l_datetime_short(t)
|
|
||||||
l_time(t)
|
l_time(t)
|
||||||
[true,false].each{|v| l_YesNo(v); l_yesno(v) }
|
[true,false].each{|v| l_YesNo(v); l_yesno(v) }
|
||||||
}
|
}
|
||||||
@@ -332,9 +347,10 @@ class GLocTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_charset_change_all
|
def test_charset_change_all
|
||||||
load_default_strings
|
load_default_strings
|
||||||
|
GLoc.clear_strings_except :en, :ja
|
||||||
GLoc.add_localized_strings :ja2, :a => 'a'
|
GLoc.add_localized_strings :ja2, :a => 'a'
|
||||||
GLoc.valid_languages # Force refresh if in dev mode
|
GLoc.valid_languages # Force refresh if in dev mode
|
||||||
GLoc.class_eval 'LOCALIZED_STRINGS[:ja2]= LOCALIZED_STRINGS[:ja].clone'
|
GLoc::Constants.class_eval 'LOCALIZED_STRINGS[:ja2]= LOCALIZED_STRINGS[:ja].clone'
|
||||||
|
|
||||||
[:ja, :ja2].each do |l|
|
[:ja, :ja2].each do |l|
|
||||||
set_language l
|
set_language l
|
||||||
@@ -357,8 +373,8 @@ class GLocTest < Test::Unit::TestCase
|
|||||||
GLoc.add_localized_strings :ja2, :a => 'a'
|
GLoc.add_localized_strings :ja2, :a => 'a'
|
||||||
GLoc.add_localized_strings :ja3, :a => 'a'
|
GLoc.add_localized_strings :ja3, :a => 'a'
|
||||||
GLoc.valid_languages # Force refresh if in dev mode
|
GLoc.valid_languages # Force refresh if in dev mode
|
||||||
GLoc.class_eval 'LOCALIZED_STRINGS[:ja2]= LOCALIZED_STRINGS[:ja].clone'
|
GLoc::Constants.class_eval 'LOCALIZED_STRINGS[:ja2]= LOCALIZED_STRINGS[:ja].clone'
|
||||||
GLoc.class_eval 'LOCALIZED_STRINGS[:ja3]= LOCALIZED_STRINGS[:ja].clone'
|
GLoc::Constants.class_eval 'LOCALIZED_STRINGS[:ja3]= LOCALIZED_STRINGS[:ja].clone'
|
||||||
|
|
||||||
[:ja, :ja2, :ja3].each do |l|
|
[:ja, :ja2, :ja3].each do |l|
|
||||||
set_language l
|
set_language l
|
||||||
@@ -411,9 +427,203 @@ class GLocTest < Test::Unit::TestCase
|
|||||||
assert_equal :en, current_language
|
assert_equal :en, current_language
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_procs_and_lambdas
|
||||||
|
GLoc.load_localized_strings File.join(File.dirname(__FILE__),'lang')
|
||||||
|
|
||||||
|
assert_equal 'There are 7 birds', ll(:en, :proc_test, 7)
|
||||||
|
assert_equal '鳥が7羽いる', ll(:ja, :proc_test, 7)
|
||||||
|
assert_equal 'My name is Golly. I am 25 years old.', ll(:en, :lambda_test, 'Golly', 25)
|
||||||
|
assert_equal '25才のGollyです。', ll(:ja, :lambda_test, 'Golly', 25)
|
||||||
|
# Lambdas REQUIRE exact number of args
|
||||||
|
assert_raises(ArgumentError) {ll(:en, :lambda_test, 'Golly')}
|
||||||
|
assert_raises(ArgumentError) {ll(:ja, :lambda_test, 'Golly', 25, 4)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_l_without_args
|
||||||
|
GLoc.add_localized_strings :en, :asd => 'arg is %d'
|
||||||
|
GLoc.add_localized_strings :ja, :asd => '%dです'
|
||||||
|
GLoc.valid_languages # Force refresh if in dev mode
|
||||||
|
set_language :en
|
||||||
|
assert_equal 'arg is %d', l_without_args(:asd)
|
||||||
|
assert_equal 'arg is %d', ltry_without_args(:asd)
|
||||||
|
assert_equal 'qwe', ltry_without_args('qwe')
|
||||||
|
assert_equal 'arg is %d', ll_without_args(:en,:asd)
|
||||||
|
assert_equal '%dです', ll_without_args(:ja,:asd)
|
||||||
|
set_language :ja
|
||||||
|
assert_equal '%dです', l_without_args(:asd)
|
||||||
|
assert_equal '%dです', ltry_without_args(:asd)
|
||||||
|
assert_equal 'qwe', ltry_without_args('qwe')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_date_select_order
|
||||||
|
load_default_strings
|
||||||
|
GLoc.valid_languages.each {|l|
|
||||||
|
set_language l
|
||||||
|
v= l(:actionview_datehelper_date_select_order)
|
||||||
|
assert_kind_of Array, v
|
||||||
|
assert_equal 3, v.size
|
||||||
|
assert v.include?(:year)
|
||||||
|
assert v.include?(:day)
|
||||||
|
assert v.include?(:month)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_arrays_and_charset_change
|
||||||
|
GLoc.load_localized_strings File.join(File.dirname(__FILE__),'lang')
|
||||||
|
GLoc.valid_languages # Force refresh if in dev mode
|
||||||
|
set_language :ja
|
||||||
|
clear_strings :ja, :proc_test, :lambda_test, :hash_test
|
||||||
|
|
||||||
|
v= l(:array_test)
|
||||||
|
assert_equal [:yay, 'はい', [1,2,'いいえ',3]], v
|
||||||
|
assert_equal "E381AFE38184", v[1].unpack('H*')[0].upcase
|
||||||
|
|
||||||
|
GLoc.set_charset 'sjis'
|
||||||
|
v= l(:array_test)
|
||||||
|
assert_kind_of Array, v
|
||||||
|
assert_equal 3, v.size
|
||||||
|
assert_equal :yay, v[0]
|
||||||
|
assert_equal "82CD82A2", v[1].unpack('H*')[0].upcase
|
||||||
|
v= v[2]
|
||||||
|
assert_kind_of Array, v
|
||||||
|
assert_equal 4, v.size
|
||||||
|
assert_equal 1, v[0]
|
||||||
|
assert_equal 2, v[1]
|
||||||
|
assert_equal "82A282A282A6", v[2].unpack('H*')[0].upcase
|
||||||
|
assert_equal 3, v[3]
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_hashes_and_charset_change
|
||||||
|
GLoc.load_localized_strings File.join(File.dirname(__FILE__),'lang')
|
||||||
|
GLoc.valid_languages # Force refresh if in dev mode
|
||||||
|
set_language :ja
|
||||||
|
clear_strings :ja, :proc_test, :lambda_test, :array_test
|
||||||
|
|
||||||
|
v= l(:hash_test)
|
||||||
|
assert_equal({'y' => 'はい', 'n' => 'いいえ', :y => 'はい', :n => 'いいえ', 2 => [:ah,'hehe','いいえ']},v)
|
||||||
|
assert_equal "E381AFE38184", v[:y].unpack('H*')[0].upcase
|
||||||
|
|
||||||
|
GLoc.set_charset 'sjis'
|
||||||
|
v= l(:hash_test)
|
||||||
|
assert_kind_of Hash, v
|
||||||
|
assert_equal 5, v.size
|
||||||
|
assert_equal "82CD82A2", v[:y].unpack('H*')[0].upcase
|
||||||
|
assert_equal [:ah,'hehe'], v[2][0..1]
|
||||||
|
assert_equal "82A282A282A6", v[2][2].unpack('H*')[0].upcase
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_lambdas_and_charset_change
|
||||||
|
GLoc.load_localized_strings File.join(File.dirname(__FILE__),'lang')
|
||||||
|
GLoc.valid_languages # Force refresh if in dev mode
|
||||||
|
set_language :ja
|
||||||
|
clear_strings :ja, :array_test, :hash_test
|
||||||
|
|
||||||
|
# UTF-8
|
||||||
|
assert_equal '鳥が15羽いる', ll(:ja, :proc_test, 15)
|
||||||
|
assert_equal '20才のBaaです。', ll(:ja, :lambda_test, 'Baa', 20)
|
||||||
|
|
||||||
|
# Shift-JIS
|
||||||
|
GLoc.set_charset 'sjis'
|
||||||
|
Iconv.open('sjis', 'utf-8') do |iconv|
|
||||||
|
assert_equal iconv.iconv('鳥が15羽いる'), ll(:ja, :proc_test, 15)
|
||||||
|
assert_equal iconv.iconv('20才のBaaです。'), ll(:ja, :lambda_test, 'Baa', 20)
|
||||||
|
end
|
||||||
|
|
||||||
|
# UTF-8
|
||||||
|
GLoc.set_charset 'utf-8'
|
||||||
|
assert_equal '鳥が15羽いる', ll(:ja, :proc_test, 15)
|
||||||
|
assert_equal '20才のBaaです。', ll(:ja, :lambda_test, 'Baa', 20)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_nonstring_basic_types
|
||||||
|
GLoc.load_localized_strings File.join(File.dirname(__FILE__),'lang')
|
||||||
|
GLoc.valid_languages # Force refresh if in dev mode
|
||||||
|
set_language :ja
|
||||||
|
|
||||||
|
assert_equal true, l(:true_test)
|
||||||
|
assert_equal false, l(:false_test)
|
||||||
|
assert_equal 52, l(:fixnum_test)
|
||||||
|
assert_equal :sweet, l(:symbol_test)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_datetime_formats
|
||||||
|
load_default_strings
|
||||||
|
GLoc.valid_languages.each do |l|
|
||||||
|
set_language l
|
||||||
|
assert_array l(:general_text_month_names), 12, true, String
|
||||||
|
assert_array l(:general_text_month_names_abbr), 12, false, String
|
||||||
|
assert_array l(:general_text_day_names), 7, true, String
|
||||||
|
assert_array l(:general_text_day_names_abbr), 7, false, String
|
||||||
|
end
|
||||||
|
GLoc.load_localized_strings File.join(File.dirname(__FILE__),'lang')
|
||||||
|
set_language :ru
|
||||||
|
t= Time.local(2006,10,13,23,58) # fri
|
||||||
|
assert_equal '%b 13/Октябрь/2006 %b', l_date(t)
|
||||||
|
assert_equal 'Окт 13 _%b:%Октябрь (2006) 11:58 PM', l_datetime(t)
|
||||||
|
set_language :ja
|
||||||
|
t= Time.local(2005,1,18,10,05) # tue
|
||||||
|
assert_equal '18/1月 火', l_date(t)
|
||||||
|
assert_equal '10:05 AM (2005) 18/1月 火曜日', l_datetime(t)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sameas
|
||||||
|
GLoc.load_localized_strings File.join(File.dirname(__FILE__),'lang')
|
||||||
|
GLoc.valid_languages # Force refresh if in dev mode
|
||||||
|
set_language :ja
|
||||||
|
GLoc.clear_strings_except :ja
|
||||||
|
|
||||||
|
test= lambda do |charset|
|
||||||
|
Iconv.open(charset,'utf-8') do |i|
|
||||||
|
assert_equal i.iconv('日本語のみ'), l(:sameas_test2)
|
||||||
|
assert_equal i.iconv('日本語のみ'), l(:sameas_test1)
|
||||||
|
assert_equal i.iconv('鳥が142羽いる'), l(:sameas_test3,142)
|
||||||
|
assert_equal i.iconv('鳥が654羽いる'), l(:sameas_test3,654)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test.call 'utf-8'
|
||||||
|
test.call 'utf-8'
|
||||||
|
GLoc.set_charset 'sjis'
|
||||||
|
test.call 'sjis'
|
||||||
|
GLoc.set_charset 'utf-8'
|
||||||
|
test.call 'utf-8'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_constants_not_inherited
|
||||||
|
assert !LClass.constants.include?("UTF8")
|
||||||
|
assert !LClass.constants.include?("RULES")
|
||||||
|
assert !LClass.constants.include?("CONFIG")
|
||||||
|
assert !LClass.constants.include?("LOCALIZED_STRINGS")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_simple_language_mode
|
||||||
|
GLoc.set_language_mode :simple
|
||||||
|
GLoc.load_localized_strings File.join(File.dirname(__FILE__),'lang')
|
||||||
|
targets= [@l1,@l2,LClass,GLoc]
|
||||||
|
set_language :en
|
||||||
|
assert_localized_value targets, 'This is in en+ja', :in_both_langs
|
||||||
|
set_language :ja
|
||||||
|
assert_localized_value targets, 'enにもjaにもある', :in_both_langs
|
||||||
|
@l1.set_language :en
|
||||||
|
assert_localized_value targets, 'This is in en+ja', :in_both_langs
|
||||||
|
GLoc.set_language :ja
|
||||||
|
assert_localized_value targets, 'enにもjaにもある', :in_both_langs
|
||||||
|
LClass.set_language :en
|
||||||
|
assert_localized_value targets, 'This is in en+ja', :in_both_langs
|
||||||
|
ensure
|
||||||
|
GLoc.set_language_mode :cascading
|
||||||
|
end
|
||||||
|
|
||||||
#===========================================================================
|
#===========================================================================
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def assert_array(array, size, unique=false, element_classes=nil)
|
||||||
|
assert_kind_of Array, array
|
||||||
|
assert_equal size, array.size
|
||||||
|
assert array.size == array.uniq.size if unique
|
||||||
|
array.each {|e| flunk unless e.is_a?(element_classes)} if element_classes
|
||||||
|
end
|
||||||
|
|
||||||
def assert_localized_value(objects,expected,key)
|
def assert_localized_value(objects,expected,key)
|
||||||
objects = [objects] unless objects.kind_of?(Array)
|
objects = [objects] unless objects.kind_of?(Array)
|
||||||
objects.each {|object|
|
objects.each {|object|
|
||||||
@@ -427,6 +637,12 @@ class GLocTest < Test::Unit::TestCase
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clear_strings(langs,*keys)
|
||||||
|
x= {}
|
||||||
|
keys.each {|k| x[k]= nil}
|
||||||
|
[langs].flatten.each {|l| GLoc.add_localized_strings l, x, true}
|
||||||
|
end
|
||||||
|
|
||||||
def load_default_strings
|
def load_default_strings
|
||||||
GLoc.load_localized_strings File.join(File.dirname(__FILE__),'..','lang')
|
GLoc.load_localized_strings File.join(File.dirname(__FILE__),'..','lang')
|
||||||
end
|
end
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
in_both_langs: This is in en+ja
|
||||||
|
en_only: English only
|
||||||
|
proc_test: !!proc '|c| "There are #{c} birds"'
|
||||||
|
lambda_test: !!lambda '|name,age| "My name is #{name}. I am #{age} years old."'
|
||||||
File renamed without changes.
@@ -0,0 +1,18 @@
|
|||||||
|
in_both_langs: enにもjaにもある
|
||||||
|
ja_only: 日本語のみ
|
||||||
|
proc_test: !!proc '|c| "鳥が#{c}羽いる"'
|
||||||
|
lambda_test: !!lambda '|name,age| "#{age}才の#{name}です。"'
|
||||||
|
array_test: [:yay, はい, [1, 2, いいえ, 3]]
|
||||||
|
symbol_test: :sweet
|
||||||
|
fixnum_test: 52
|
||||||
|
true_test: true
|
||||||
|
false_test: false
|
||||||
|
general_fmt_date: !!datetime_fmt '%d/%B %a'
|
||||||
|
general_fmt_datetime: !!datetime_fmt '%I:%M %p (%Y) %d/%b %A'
|
||||||
|
sameas_test1: !!sameas sameas_test2
|
||||||
|
sameas_test2: !!sameas ja_only
|
||||||
|
sameas_test3: !!sameas proc_test
|
||||||
|
hash_test:
|
||||||
|
y: はい
|
||||||
|
n: いいえ
|
||||||
|
2: [:ah, hehe, いいえ]
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
general_fmt_date: !!datetime_fmt '%%b %d/%B/%Y %%b'
|
||||||
|
general_fmt_datetime: !!datetime_fmt '%b %d _%%b:%%%B (%Y) %I:%M %p'
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
en_only: overriden dude
|
||||||
|
new_en: This is a new English string
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
in_both_langs: 更新された
|
||||||
|
new_ja: 新たな日本語ストリング
|
||||||
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user