ShogunPanda/lazier

View on GitHub
docs/Lazier/I18n.html

Summary

Maintainability
Test Coverage
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
  Class: Lazier::I18n
  
    &mdash; Documentation by YARD 0.9.5
  
</title>

  <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />

  <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  pathId = "Lazier::I18n";
  relpath = '../';
</script>


  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>


  </head>
  <body>
    <div class="nav_wrap">
      <iframe id="nav" src="../class_list.html"></iframe>
      <div id="resizer"></div>
    </div>

    <div id="main" tabindex="-1">
      <div id="header">
        <div id="menu">
  
    <a href="../_index.html">Index (I)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../Lazier.html" title="Lazier (module)">Lazier</a></span></span>
     &raquo; 
    <span class="title">I18n</span>
  
</div>

        <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="../class_list.html">

        <svg width="24" height="24">
          <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
          <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
          <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
        </svg>
    </a>
  
</div>
        <div class="clear"></div>
      </div>

      <iframe id="search_frame" src="../class_list.html"></iframe>

      <div id="content"><h1>Class: Lazier::I18n
  
  
  
</h1>
<div class="box_info">
  
  <dl>
    <dt>Inherits:</dt>
    <dd>
      <span class="inheritName">Object</span>
      
        <ul class="fullTree">
          <li>Object</li>
          
            <li class="next">Lazier::I18n</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
    </dd>
  </dl>
  

  
  
  
  
  

  

  
  <dl>
    <dt>Defined in:</dt>
    <dd>lib/lazier/i18n.rb</dd>
  </dl>
  
</div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    <p>Provides an easy way to localized messages in a class.</p>


  </div>
</div>
<div class="tags">
  

</div>



  <h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2>
  <ul class="summary">
    
      <li class="public ">
  <span class="summary_signature">
    
      <a href="#backend-instance_method" title="#backend (instance method)">#<strong>backend</strong>  &#x21d2; I18n::Backend </a>
    

    
  </span>
  
  
  
    
      <span class="note title readonly">readonly</span>
    
    
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>The backend used for translations.</p>
</div></span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature">
    
      <a href="#locale-instance_method" title="#locale (instance method)">#<strong>locale</strong>  &#x21d2; String|Symbol|nil </a>
    

    
  </span>
  
  
  
    
    
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>The current locale.</p>
</div></span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature">
    
      <a href="#path-instance_method" title="#path (instance method)">#<strong>path</strong>  &#x21d2; String </a>
    

    
  </span>
  
  
  
    
      <span class="note title readonly">readonly</span>
    
    
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>The path where the translations are stored.</p>
</div></span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature">
    
      <a href="#root-instance_method" title="#root (instance method)">#<strong>root</strong>  &#x21d2; Symbol </a>
    

    
  </span>
  
  
  
    
      <span class="note title readonly">readonly</span>
    
    
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>The root level of the translation.</p>
</div></span>
  
</li>

    
  </ul>




  
    <h2>
      Class Method Summary
      <small><a href="#" class="summary_toggle">collapse</a></small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#instance-class_method" title="instance (class method)">.<strong>instance</strong>(locale = nil, root: :lazier, path: nil, force: false)  &#x21d2; I18n </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>Returns the singleton instance of the settings.</p>
</div></span>
  
</li>

      
    </ul>
  
    <h2>
      Instance Method Summary
      <small><a href="#" class="summary_toggle">collapse</a></small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(locale = nil, root: :lazier, path: nil)  &#x21d2; I18n </a>
    

    
  </span>
  
  
    <span class="note title constructor">constructor</span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>Creates a new I18n object.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#locales-instance_method" title="#locales (instance method)">#<strong>locales</strong>  &#x21d2; Array </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>Get the list of available translation for a locale.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#reload-instance_method" title="#reload (instance method)">#<strong>reload</strong>  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>Reloads all the I18n translations.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#translate-instance_method" title="#translate (instance method)">#<strong>translate</strong>(message, **args)  &#x21d2; String </a>
    

    
      (also: #t)
    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>Localize a message.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#translate_in_locale-instance_method" title="#translate_in_locale (instance method)">#<strong>translate_in_locale</strong>(locale, message, *args)  &#x21d2; String </a>
    

    
      (also: #tl)
    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>Localize a message in a specific locale.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#translations-instance_method" title="#translations (instance method)">#<strong>translations</strong>(locale = nil)  &#x21d2; Hash </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>Gets the list of available translation for a locale.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#with_locale-instance_method" title="#with_locale (instance method)">#<strong>with_locale</strong>(locale)  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>Temporary sets a different locale and execute the given block.</p>
</div></span>
  
</li>

      
    </ul>
  

<div id="constructor_details" class="method_details_list">
  <h2>Constructor Details</h2>
  
    <div class="method_details first">
  <h3 class="signature first" id="initialize-instance_method">
  
    #<strong>initialize</strong>(locale = nil, root: :lazier, path: nil)  &#x21d2; <tt><span class='object_link'><a href="" title="Lazier::I18n (class)">I18n</a></span></tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Creates a new I18n object.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>locale</span>
      
      
        <span class='type'>(<tt>Symbol|NilClass</tt>)</span>
      
      
        <em class="default">(defaults to: <tt>nil</tt>)</em>
      
      
        &mdash;
        <div class='inline'><p>The locale to use. Defaults to the current locale.</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>root</span>
      
      
        <span class='type'>(<tt>Symbol</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The root level of the translation.</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>path</span>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span>|NilClass</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The path where the translations are stored.</p>
</div>
      
    </li>
  
</ul>


</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


41
42
43
44
45
46
47
48
49
50</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/lazier/i18n.rb', line 41</span>

<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='symbol'>:lazier</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
  <span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_load_object'>load_object</span>
  <span class='id identifier rubyid_path'>path</span> <span class='op'>||=</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>ROOT</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>/locales</span><span class='tstring_end'>&quot;</span></span>
  <span class='ivar'>@root</span> <span class='op'>=</span> <span class='id identifier rubyid_root'>root</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
  <span class='ivar'>@path</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>

  <span class='id identifier rubyid_setup_backend'>setup_backend</span>

  <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>||</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_default_locale'>default_locale</span> <span class='op'>||</span> <span class='id identifier rubyid_system_locale'>system_locale</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
  
</div>

  <div id="instance_attr_details" class="attr_details">
    <h2>Instance Attribute Details</h2>
    
      
      <span id=""></span>
      <div class="method_details first">
  <h3 class="signature first" id="backend-instance_method">
  
    #<strong>backend</strong>  &#x21d2; <tt>I18n::Backend</tt>  <span class="extras">(readonly)</span>
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Returns The backend used for translations.</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>I18n::Backend</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The backend used for translations.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/lazier/i18n.rb', line 17</span>

<span class='kw'>class</span> <span class='const'>I18n</span>
  <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:locale</span>
  <span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:root</span><span class='comma'>,</span> <span class='symbol'>:path</span><span class='comma'>,</span> <span class='symbol'>:backend</span>

  <span class='comment'># The default locale for new instances.
</span>  <span class='id identifier rubyid_mattr_accessor'>mattr_accessor</span> <span class='symbol'>:default_locale</span>

  <span class='comment'># Returns the singleton instance of the settings.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [Symbol|NilClass] The locale to use for translations. Default is the current system locale.
</span>  <span class='comment'># @param root [Symbol] The root level of the translation.
</span>  <span class='comment'># @param path [String|NilClass] The path where the translations are stored.
</span>  <span class='comment'># @param force [Boolean] Whether to force recreation of the instance.
</span>  <span class='comment'># @return [I18n] The singleton instance of the i18n.
</span>  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='symbol'>:lazier</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>force:</span> <span class='kw'>false</span><span class='rparen'>)</span>
    <span class='ivar'>@instance</span> <span class='op'>=</span> <span class='kw'>nil</span> <span class='kw'>if</span> <span class='id identifier rubyid_force'>force</span>
    <span class='ivar'>@instance</span> <span class='op'>||=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='id identifier rubyid_root'>root</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span>
  <span class='kw'>end</span>

  <span class='comment'># Creates a new I18n object.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [Symbol|NilClass] The locale to use. Defaults to the current locale.
</span>  <span class='comment'># @param root [Symbol] The root level of the translation.
</span>  <span class='comment'># @param path [String|NilClass] The path where the translations are stored.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='symbol'>:lazier</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
    <span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_load_object'>load_object</span>
    <span class='id identifier rubyid_path'>path</span> <span class='op'>||=</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>ROOT</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>/locales</span><span class='tstring_end'>&quot;</span></span>
    <span class='ivar'>@root</span> <span class='op'>=</span> <span class='id identifier rubyid_root'>root</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
    <span class='ivar'>@path</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>

    <span class='id identifier rubyid_setup_backend'>setup_backend</span>

    <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>||</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_default_locale'>default_locale</span> <span class='op'>||</span> <span class='id identifier rubyid_system_locale'>system_locale</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
  <span class='kw'>end</span>

  <span class='comment'># Reloads all the I18n translations.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_reload'>reload</span>
    <span class='comment'># Extract the backend to an attribute
</span>    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_backend'>backend</span><span class='period'>.</span><span class='id identifier rubyid_load_translations'>load_translations</span>
  <span class='kw'>end</span>

  <span class='comment'># Gets the list of available translation for a locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [Symbol|NilClass] The locale to list. Defaults to the current locale.
</span>  <span class='comment'># @return [Hash] The available translations for the specified locale.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_translations'>translations</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_locale'>locale</span> <span class='op'>||=</span> <span class='ivar'>@locale</span>
    <span class='ivar'>@backend</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='symbol'>:translations</span><span class='rparen'>)</span><span class='lbracket'>[</span><span class='id identifier rubyid_locale'>locale</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
  <span class='kw'>end</span>

  <span class='comment'># Sets the current locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param value [Symbol] The locale to use for translations. Default is the current system locale.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_locale='>locale=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
    <span class='ivar'>@locale</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='ivar'>@locale</span>
  <span class='kw'>end</span>

  <span class='comment'># Get the list of available translation for a locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @return [Array] The list of available locales.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_locales'>locales</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_available_locales'>available_locales</span>
  <span class='kw'>end</span>

  <span class='comment'># Localize a message.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param message [String|Symbol] The message to localize.
</span>  <span class='comment'># @param args [Array] Optional arguments to localize the message.
</span>  <span class='comment'># @return [String] The localized message.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
    <span class='comment'># PI: Ignore reek on this.
</span>    <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_root'>root</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>!~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^(\.|::)</span><span class='regexp_end'>/</span></span>

    <span class='kw'>begin</span>
      <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='label'>raise:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='rparen'>)</span>
    <span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>I18n</span><span class='op'>::</span><span class='const'>MissingTranslationData</span>
      <span class='id identifier rubyid_raise'>raise</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Exceptions</span><span class='op'>::</span><span class='const'>MissingTranslation</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rbracket'>]</span>
    <span class='kw'>end</span>
  <span class='kw'>end</span>
  <span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:t</span><span class='comma'>,</span> <span class='symbol'>:translate</span>

  <span class='comment'># Localize a message in a specific locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [String|Symbol] The new locale to use for localization.
</span>  <span class='comment'># @param message [String|Symbol] The message to localize.
</span>  <span class='comment'># @param args [Array] Optional arguments to localize the message.
</span>  <span class='comment'># @return [String] The localized message.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_translate_in_locale'>translate_in_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_with_locale'>with_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
  <span class='kw'>end</span>
  <span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:tl</span><span class='comma'>,</span> <span class='symbol'>:translate_in_locale</span>

  <span class='comment'># Temporary sets a different locale and execute the given block.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [String|Symbol] The new locale to use for localization.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_with_locale'>with_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_old_locale'>old_locale</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span>

    <span class='kw'>begin</span>
      <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_locale'>locale</span>
      <span class='kw'>return</span> <span class='kw'>yield</span>
    <span class='kw'>ensure</span>
      <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_old_locale'>old_locale</span>
    <span class='kw'>end</span>
  <span class='kw'>end</span>

  <span class='id identifier rubyid_private'>private</span>

  <span class='comment'># :nodoc:
</span>  <span class='const'>OSX_DETECTION</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>defaults read .GlobalPreferences AppleLanguages | awk &#39;NR==2{gsub(/[ ,]/, \&quot;\&quot;);print}&#39;</span><span class='tstring_end'>&quot;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale'>system_locale</span>
    <span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_platform'>platform</span>

    <span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:java</span><span class='comma'>,</span> <span class='symbol'>:osx</span><span class='comma'>,</span> <span class='symbol'>:posix</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>system_locale_</span><span class='embexpr_beg'>#{</span><span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
    <span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>RuntimeError</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
    <span class='id identifier rubyid_rv'>rv</span>
  <span class='kw'>rescue</span>
    <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>en</span><span class='tstring_end'>&quot;</span></span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale_java'>system_locale_java</span>
    <span class='const'>Java</span><span class='period'>.</span><span class='id identifier rubyid_java'>java</span><span class='period'>.</span><span class='id identifier rubyid_util'>util</span><span class='period'>.</span><span class='const'>Locale</span><span class='period'>.</span><span class='id identifier rubyid_getDefault'>getDefault</span><span class='period'>.</span><span class='id identifier rubyid_toString'>toString</span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale_osx'>system_locale_osx</span>
    <span class='backtick'>`</span><span class='embexpr_beg'>#{</span><span class='const'>OSX_DETECTION</span><span class='embexpr_end'>}</span><span class='tstring_end'>`</span></span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale_posix'>system_locale_posix</span>
    <span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>LANG</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_setup_backend'>setup_backend</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_load_path'>load_path</span> <span class='op'>+=</span> <span class='const'>Dir</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='ivar'>@path</span><span class='embexpr_end'>}</span><span class='tstring_content'>/*.yml</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_load_path'>load_path</span><span class='period'>.</span><span class='id identifier rubyid_uniq!'>uniq!</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_exception_handler'>exception_handler</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Exceptions</span><span class='op'>::</span><span class='const'>TranslationExceptionHandler</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
    <span class='id identifier rubyid_reload'>reload</span>

    <span class='ivar'>@backend</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_backend'>backend</span>
  <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      
      <span id="locale=-instance_method"></span>
      <div class="method_details ">
  <h3 class="signature " id="locale-instance_method">
  
    #<strong>locale</strong>  &#x21d2; <tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span>|Symbol|nil</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Returns The current locale.</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span>|Symbol|nil</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The current locale.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/lazier/i18n.rb', line 17</span>

<span class='kw'>class</span> <span class='const'>I18n</span>
  <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:locale</span>
  <span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:root</span><span class='comma'>,</span> <span class='symbol'>:path</span><span class='comma'>,</span> <span class='symbol'>:backend</span>

  <span class='comment'># The default locale for new instances.
</span>  <span class='id identifier rubyid_mattr_accessor'>mattr_accessor</span> <span class='symbol'>:default_locale</span>

  <span class='comment'># Returns the singleton instance of the settings.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [Symbol|NilClass] The locale to use for translations. Default is the current system locale.
</span>  <span class='comment'># @param root [Symbol] The root level of the translation.
</span>  <span class='comment'># @param path [String|NilClass] The path where the translations are stored.
</span>  <span class='comment'># @param force [Boolean] Whether to force recreation of the instance.
</span>  <span class='comment'># @return [I18n] The singleton instance of the i18n.
</span>  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='symbol'>:lazier</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>force:</span> <span class='kw'>false</span><span class='rparen'>)</span>
    <span class='ivar'>@instance</span> <span class='op'>=</span> <span class='kw'>nil</span> <span class='kw'>if</span> <span class='id identifier rubyid_force'>force</span>
    <span class='ivar'>@instance</span> <span class='op'>||=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='id identifier rubyid_root'>root</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span>
  <span class='kw'>end</span>

  <span class='comment'># Creates a new I18n object.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [Symbol|NilClass] The locale to use. Defaults to the current locale.
</span>  <span class='comment'># @param root [Symbol] The root level of the translation.
</span>  <span class='comment'># @param path [String|NilClass] The path where the translations are stored.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='symbol'>:lazier</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
    <span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_load_object'>load_object</span>
    <span class='id identifier rubyid_path'>path</span> <span class='op'>||=</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>ROOT</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>/locales</span><span class='tstring_end'>&quot;</span></span>
    <span class='ivar'>@root</span> <span class='op'>=</span> <span class='id identifier rubyid_root'>root</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
    <span class='ivar'>@path</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>

    <span class='id identifier rubyid_setup_backend'>setup_backend</span>

    <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>||</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_default_locale'>default_locale</span> <span class='op'>||</span> <span class='id identifier rubyid_system_locale'>system_locale</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
  <span class='kw'>end</span>

  <span class='comment'># Reloads all the I18n translations.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_reload'>reload</span>
    <span class='comment'># Extract the backend to an attribute
</span>    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_backend'>backend</span><span class='period'>.</span><span class='id identifier rubyid_load_translations'>load_translations</span>
  <span class='kw'>end</span>

  <span class='comment'># Gets the list of available translation for a locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [Symbol|NilClass] The locale to list. Defaults to the current locale.
</span>  <span class='comment'># @return [Hash] The available translations for the specified locale.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_translations'>translations</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_locale'>locale</span> <span class='op'>||=</span> <span class='ivar'>@locale</span>
    <span class='ivar'>@backend</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='symbol'>:translations</span><span class='rparen'>)</span><span class='lbracket'>[</span><span class='id identifier rubyid_locale'>locale</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
  <span class='kw'>end</span>

  <span class='comment'># Sets the current locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param value [Symbol] The locale to use for translations. Default is the current system locale.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_locale='>locale=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
    <span class='ivar'>@locale</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='ivar'>@locale</span>
  <span class='kw'>end</span>

  <span class='comment'># Get the list of available translation for a locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @return [Array] The list of available locales.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_locales'>locales</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_available_locales'>available_locales</span>
  <span class='kw'>end</span>

  <span class='comment'># Localize a message.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param message [String|Symbol] The message to localize.
</span>  <span class='comment'># @param args [Array] Optional arguments to localize the message.
</span>  <span class='comment'># @return [String] The localized message.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
    <span class='comment'># PI: Ignore reek on this.
</span>    <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_root'>root</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>!~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^(\.|::)</span><span class='regexp_end'>/</span></span>

    <span class='kw'>begin</span>
      <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='label'>raise:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='rparen'>)</span>
    <span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>I18n</span><span class='op'>::</span><span class='const'>MissingTranslationData</span>
      <span class='id identifier rubyid_raise'>raise</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Exceptions</span><span class='op'>::</span><span class='const'>MissingTranslation</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rbracket'>]</span>
    <span class='kw'>end</span>
  <span class='kw'>end</span>
  <span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:t</span><span class='comma'>,</span> <span class='symbol'>:translate</span>

  <span class='comment'># Localize a message in a specific locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [String|Symbol] The new locale to use for localization.
</span>  <span class='comment'># @param message [String|Symbol] The message to localize.
</span>  <span class='comment'># @param args [Array] Optional arguments to localize the message.
</span>  <span class='comment'># @return [String] The localized message.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_translate_in_locale'>translate_in_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_with_locale'>with_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
  <span class='kw'>end</span>
  <span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:tl</span><span class='comma'>,</span> <span class='symbol'>:translate_in_locale</span>

  <span class='comment'># Temporary sets a different locale and execute the given block.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [String|Symbol] The new locale to use for localization.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_with_locale'>with_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_old_locale'>old_locale</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span>

    <span class='kw'>begin</span>
      <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_locale'>locale</span>
      <span class='kw'>return</span> <span class='kw'>yield</span>
    <span class='kw'>ensure</span>
      <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_old_locale'>old_locale</span>
    <span class='kw'>end</span>
  <span class='kw'>end</span>

  <span class='id identifier rubyid_private'>private</span>

  <span class='comment'># :nodoc:
</span>  <span class='const'>OSX_DETECTION</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>defaults read .GlobalPreferences AppleLanguages | awk &#39;NR==2{gsub(/[ ,]/, \&quot;\&quot;);print}&#39;</span><span class='tstring_end'>&quot;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale'>system_locale</span>
    <span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_platform'>platform</span>

    <span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:java</span><span class='comma'>,</span> <span class='symbol'>:osx</span><span class='comma'>,</span> <span class='symbol'>:posix</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>system_locale_</span><span class='embexpr_beg'>#{</span><span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
    <span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>RuntimeError</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
    <span class='id identifier rubyid_rv'>rv</span>
  <span class='kw'>rescue</span>
    <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>en</span><span class='tstring_end'>&quot;</span></span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale_java'>system_locale_java</span>
    <span class='const'>Java</span><span class='period'>.</span><span class='id identifier rubyid_java'>java</span><span class='period'>.</span><span class='id identifier rubyid_util'>util</span><span class='period'>.</span><span class='const'>Locale</span><span class='period'>.</span><span class='id identifier rubyid_getDefault'>getDefault</span><span class='period'>.</span><span class='id identifier rubyid_toString'>toString</span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale_osx'>system_locale_osx</span>
    <span class='backtick'>`</span><span class='embexpr_beg'>#{</span><span class='const'>OSX_DETECTION</span><span class='embexpr_end'>}</span><span class='tstring_end'>`</span></span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale_posix'>system_locale_posix</span>
    <span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>LANG</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_setup_backend'>setup_backend</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_load_path'>load_path</span> <span class='op'>+=</span> <span class='const'>Dir</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='ivar'>@path</span><span class='embexpr_end'>}</span><span class='tstring_content'>/*.yml</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_load_path'>load_path</span><span class='period'>.</span><span class='id identifier rubyid_uniq!'>uniq!</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_exception_handler'>exception_handler</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Exceptions</span><span class='op'>::</span><span class='const'>TranslationExceptionHandler</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
    <span class='id identifier rubyid_reload'>reload</span>

    <span class='ivar'>@backend</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_backend'>backend</span>
  <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      
      <span id=""></span>
      <div class="method_details ">
  <h3 class="signature " id="path-instance_method">
  
    #<strong>path</strong>  &#x21d2; <tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span></tt>  <span class="extras">(readonly)</span>
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Returns The path where the translations are stored.</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The path where the translations are stored.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/lazier/i18n.rb', line 17</span>

<span class='kw'>class</span> <span class='const'>I18n</span>
  <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:locale</span>
  <span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:root</span><span class='comma'>,</span> <span class='symbol'>:path</span><span class='comma'>,</span> <span class='symbol'>:backend</span>

  <span class='comment'># The default locale for new instances.
</span>  <span class='id identifier rubyid_mattr_accessor'>mattr_accessor</span> <span class='symbol'>:default_locale</span>

  <span class='comment'># Returns the singleton instance of the settings.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [Symbol|NilClass] The locale to use for translations. Default is the current system locale.
</span>  <span class='comment'># @param root [Symbol] The root level of the translation.
</span>  <span class='comment'># @param path [String|NilClass] The path where the translations are stored.
</span>  <span class='comment'># @param force [Boolean] Whether to force recreation of the instance.
</span>  <span class='comment'># @return [I18n] The singleton instance of the i18n.
</span>  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='symbol'>:lazier</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>force:</span> <span class='kw'>false</span><span class='rparen'>)</span>
    <span class='ivar'>@instance</span> <span class='op'>=</span> <span class='kw'>nil</span> <span class='kw'>if</span> <span class='id identifier rubyid_force'>force</span>
    <span class='ivar'>@instance</span> <span class='op'>||=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='id identifier rubyid_root'>root</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span>
  <span class='kw'>end</span>

  <span class='comment'># Creates a new I18n object.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [Symbol|NilClass] The locale to use. Defaults to the current locale.
</span>  <span class='comment'># @param root [Symbol] The root level of the translation.
</span>  <span class='comment'># @param path [String|NilClass] The path where the translations are stored.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='symbol'>:lazier</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
    <span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_load_object'>load_object</span>
    <span class='id identifier rubyid_path'>path</span> <span class='op'>||=</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>ROOT</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>/locales</span><span class='tstring_end'>&quot;</span></span>
    <span class='ivar'>@root</span> <span class='op'>=</span> <span class='id identifier rubyid_root'>root</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
    <span class='ivar'>@path</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>

    <span class='id identifier rubyid_setup_backend'>setup_backend</span>

    <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>||</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_default_locale'>default_locale</span> <span class='op'>||</span> <span class='id identifier rubyid_system_locale'>system_locale</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
  <span class='kw'>end</span>

  <span class='comment'># Reloads all the I18n translations.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_reload'>reload</span>
    <span class='comment'># Extract the backend to an attribute
</span>    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_backend'>backend</span><span class='period'>.</span><span class='id identifier rubyid_load_translations'>load_translations</span>
  <span class='kw'>end</span>

  <span class='comment'># Gets the list of available translation for a locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [Symbol|NilClass] The locale to list. Defaults to the current locale.
</span>  <span class='comment'># @return [Hash] The available translations for the specified locale.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_translations'>translations</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_locale'>locale</span> <span class='op'>||=</span> <span class='ivar'>@locale</span>
    <span class='ivar'>@backend</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='symbol'>:translations</span><span class='rparen'>)</span><span class='lbracket'>[</span><span class='id identifier rubyid_locale'>locale</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
  <span class='kw'>end</span>

  <span class='comment'># Sets the current locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param value [Symbol] The locale to use for translations. Default is the current system locale.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_locale='>locale=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
    <span class='ivar'>@locale</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='ivar'>@locale</span>
  <span class='kw'>end</span>

  <span class='comment'># Get the list of available translation for a locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @return [Array] The list of available locales.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_locales'>locales</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_available_locales'>available_locales</span>
  <span class='kw'>end</span>

  <span class='comment'># Localize a message.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param message [String|Symbol] The message to localize.
</span>  <span class='comment'># @param args [Array] Optional arguments to localize the message.
</span>  <span class='comment'># @return [String] The localized message.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
    <span class='comment'># PI: Ignore reek on this.
</span>    <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_root'>root</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>!~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^(\.|::)</span><span class='regexp_end'>/</span></span>

    <span class='kw'>begin</span>
      <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='label'>raise:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='rparen'>)</span>
    <span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>I18n</span><span class='op'>::</span><span class='const'>MissingTranslationData</span>
      <span class='id identifier rubyid_raise'>raise</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Exceptions</span><span class='op'>::</span><span class='const'>MissingTranslation</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rbracket'>]</span>
    <span class='kw'>end</span>
  <span class='kw'>end</span>
  <span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:t</span><span class='comma'>,</span> <span class='symbol'>:translate</span>

  <span class='comment'># Localize a message in a specific locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [String|Symbol] The new locale to use for localization.
</span>  <span class='comment'># @param message [String|Symbol] The message to localize.
</span>  <span class='comment'># @param args [Array] Optional arguments to localize the message.
</span>  <span class='comment'># @return [String] The localized message.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_translate_in_locale'>translate_in_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_with_locale'>with_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
  <span class='kw'>end</span>
  <span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:tl</span><span class='comma'>,</span> <span class='symbol'>:translate_in_locale</span>

  <span class='comment'># Temporary sets a different locale and execute the given block.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [String|Symbol] The new locale to use for localization.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_with_locale'>with_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_old_locale'>old_locale</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span>

    <span class='kw'>begin</span>
      <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_locale'>locale</span>
      <span class='kw'>return</span> <span class='kw'>yield</span>
    <span class='kw'>ensure</span>
      <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_old_locale'>old_locale</span>
    <span class='kw'>end</span>
  <span class='kw'>end</span>

  <span class='id identifier rubyid_private'>private</span>

  <span class='comment'># :nodoc:
</span>  <span class='const'>OSX_DETECTION</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>defaults read .GlobalPreferences AppleLanguages | awk &#39;NR==2{gsub(/[ ,]/, \&quot;\&quot;);print}&#39;</span><span class='tstring_end'>&quot;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale'>system_locale</span>
    <span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_platform'>platform</span>

    <span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:java</span><span class='comma'>,</span> <span class='symbol'>:osx</span><span class='comma'>,</span> <span class='symbol'>:posix</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>system_locale_</span><span class='embexpr_beg'>#{</span><span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
    <span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>RuntimeError</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
    <span class='id identifier rubyid_rv'>rv</span>
  <span class='kw'>rescue</span>
    <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>en</span><span class='tstring_end'>&quot;</span></span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale_java'>system_locale_java</span>
    <span class='const'>Java</span><span class='period'>.</span><span class='id identifier rubyid_java'>java</span><span class='period'>.</span><span class='id identifier rubyid_util'>util</span><span class='period'>.</span><span class='const'>Locale</span><span class='period'>.</span><span class='id identifier rubyid_getDefault'>getDefault</span><span class='period'>.</span><span class='id identifier rubyid_toString'>toString</span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale_osx'>system_locale_osx</span>
    <span class='backtick'>`</span><span class='embexpr_beg'>#{</span><span class='const'>OSX_DETECTION</span><span class='embexpr_end'>}</span><span class='tstring_end'>`</span></span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale_posix'>system_locale_posix</span>
    <span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>LANG</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_setup_backend'>setup_backend</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_load_path'>load_path</span> <span class='op'>+=</span> <span class='const'>Dir</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='ivar'>@path</span><span class='embexpr_end'>}</span><span class='tstring_content'>/*.yml</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_load_path'>load_path</span><span class='period'>.</span><span class='id identifier rubyid_uniq!'>uniq!</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_exception_handler'>exception_handler</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Exceptions</span><span class='op'>::</span><span class='const'>TranslationExceptionHandler</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
    <span class='id identifier rubyid_reload'>reload</span>

    <span class='ivar'>@backend</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_backend'>backend</span>
  <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      
      <span id=""></span>
      <div class="method_details ">
  <h3 class="signature " id="root-instance_method">
  
    #<strong>root</strong>  &#x21d2; <tt>Symbol</tt>  <span class="extras">(readonly)</span>
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Returns The root level of the translation.</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Symbol</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The root level of the translation.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/lazier/i18n.rb', line 17</span>

<span class='kw'>class</span> <span class='const'>I18n</span>
  <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:locale</span>
  <span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:root</span><span class='comma'>,</span> <span class='symbol'>:path</span><span class='comma'>,</span> <span class='symbol'>:backend</span>

  <span class='comment'># The default locale for new instances.
</span>  <span class='id identifier rubyid_mattr_accessor'>mattr_accessor</span> <span class='symbol'>:default_locale</span>

  <span class='comment'># Returns the singleton instance of the settings.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [Symbol|NilClass] The locale to use for translations. Default is the current system locale.
</span>  <span class='comment'># @param root [Symbol] The root level of the translation.
</span>  <span class='comment'># @param path [String|NilClass] The path where the translations are stored.
</span>  <span class='comment'># @param force [Boolean] Whether to force recreation of the instance.
</span>  <span class='comment'># @return [I18n] The singleton instance of the i18n.
</span>  <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='symbol'>:lazier</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>force:</span> <span class='kw'>false</span><span class='rparen'>)</span>
    <span class='ivar'>@instance</span> <span class='op'>=</span> <span class='kw'>nil</span> <span class='kw'>if</span> <span class='id identifier rubyid_force'>force</span>
    <span class='ivar'>@instance</span> <span class='op'>||=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='id identifier rubyid_root'>root</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span>
  <span class='kw'>end</span>

  <span class='comment'># Creates a new I18n object.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [Symbol|NilClass] The locale to use. Defaults to the current locale.
</span>  <span class='comment'># @param root [Symbol] The root level of the translation.
</span>  <span class='comment'># @param path [String|NilClass] The path where the translations are stored.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='symbol'>:lazier</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
    <span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_load_object'>load_object</span>
    <span class='id identifier rubyid_path'>path</span> <span class='op'>||=</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>ROOT</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>/locales</span><span class='tstring_end'>&quot;</span></span>
    <span class='ivar'>@root</span> <span class='op'>=</span> <span class='id identifier rubyid_root'>root</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
    <span class='ivar'>@path</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_absolute_path'>absolute_path</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>

    <span class='id identifier rubyid_setup_backend'>setup_backend</span>

    <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>||</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_default_locale'>default_locale</span> <span class='op'>||</span> <span class='id identifier rubyid_system_locale'>system_locale</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
  <span class='kw'>end</span>

  <span class='comment'># Reloads all the I18n translations.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_reload'>reload</span>
    <span class='comment'># Extract the backend to an attribute
</span>    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_backend'>backend</span><span class='period'>.</span><span class='id identifier rubyid_load_translations'>load_translations</span>
  <span class='kw'>end</span>

  <span class='comment'># Gets the list of available translation for a locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [Symbol|NilClass] The locale to list. Defaults to the current locale.
</span>  <span class='comment'># @return [Hash] The available translations for the specified locale.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_translations'>translations</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_locale'>locale</span> <span class='op'>||=</span> <span class='ivar'>@locale</span>
    <span class='ivar'>@backend</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='symbol'>:translations</span><span class='rparen'>)</span><span class='lbracket'>[</span><span class='id identifier rubyid_locale'>locale</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
  <span class='kw'>end</span>

  <span class='comment'># Sets the current locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param value [Symbol] The locale to use for translations. Default is the current system locale.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_locale='>locale=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
    <span class='ivar'>@locale</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='ivar'>@locale</span>
  <span class='kw'>end</span>

  <span class='comment'># Get the list of available translation for a locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @return [Array] The list of available locales.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_locales'>locales</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_available_locales'>available_locales</span>
  <span class='kw'>end</span>

  <span class='comment'># Localize a message.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param message [String|Symbol] The message to localize.
</span>  <span class='comment'># @param args [Array] Optional arguments to localize the message.
</span>  <span class='comment'># @return [String] The localized message.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
    <span class='comment'># PI: Ignore reek on this.
</span>    <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_root'>root</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>!~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^(\.|::)</span><span class='regexp_end'>/</span></span>

    <span class='kw'>begin</span>
      <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='label'>raise:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='rparen'>)</span>
    <span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>I18n</span><span class='op'>::</span><span class='const'>MissingTranslationData</span>
      <span class='id identifier rubyid_raise'>raise</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Exceptions</span><span class='op'>::</span><span class='const'>MissingTranslation</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rbracket'>]</span>
    <span class='kw'>end</span>
  <span class='kw'>end</span>
  <span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:t</span><span class='comma'>,</span> <span class='symbol'>:translate</span>

  <span class='comment'># Localize a message in a specific locale.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [String|Symbol] The new locale to use for localization.
</span>  <span class='comment'># @param message [String|Symbol] The message to localize.
</span>  <span class='comment'># @param args [Array] Optional arguments to localize the message.
</span>  <span class='comment'># @return [String] The localized message.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_translate_in_locale'>translate_in_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_with_locale'>with_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
  <span class='kw'>end</span>
  <span class='id identifier rubyid_alias_method'>alias_method</span> <span class='symbol'>:tl</span><span class='comma'>,</span> <span class='symbol'>:translate_in_locale</span>

  <span class='comment'># Temporary sets a different locale and execute the given block.
</span>  <span class='comment'>#
</span>  <span class='comment'># @param locale [String|Symbol] The new locale to use for localization.
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_with_locale'>with_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_old_locale'>old_locale</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span>

    <span class='kw'>begin</span>
      <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_locale'>locale</span>
      <span class='kw'>return</span> <span class='kw'>yield</span>
    <span class='kw'>ensure</span>
      <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_old_locale'>old_locale</span>
    <span class='kw'>end</span>
  <span class='kw'>end</span>

  <span class='id identifier rubyid_private'>private</span>

  <span class='comment'># :nodoc:
</span>  <span class='const'>OSX_DETECTION</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>defaults read .GlobalPreferences AppleLanguages | awk &#39;NR==2{gsub(/[ ,]/, \&quot;\&quot;);print}&#39;</span><span class='tstring_end'>&quot;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale'>system_locale</span>
    <span class='id identifier rubyid_platform'>platform</span> <span class='op'>=</span> <span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_platform'>platform</span>

    <span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='symbol'>:java</span><span class='comma'>,</span> <span class='symbol'>:osx</span><span class='comma'>,</span> <span class='symbol'>:posix</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_platform'>platform</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>system_locale_</span><span class='embexpr_beg'>#{</span><span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_platform'>platform</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>nil</span>
    <span class='id identifier rubyid_raise'>raise</span><span class='lparen'>(</span><span class='const'>RuntimeError</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
    <span class='id identifier rubyid_rv'>rv</span>
  <span class='kw'>rescue</span>
    <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>en</span><span class='tstring_end'>&quot;</span></span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale_java'>system_locale_java</span>
    <span class='const'>Java</span><span class='period'>.</span><span class='id identifier rubyid_java'>java</span><span class='period'>.</span><span class='id identifier rubyid_util'>util</span><span class='period'>.</span><span class='const'>Locale</span><span class='period'>.</span><span class='id identifier rubyid_getDefault'>getDefault</span><span class='period'>.</span><span class='id identifier rubyid_toString'>toString</span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale_osx'>system_locale_osx</span>
    <span class='backtick'>`</span><span class='embexpr_beg'>#{</span><span class='const'>OSX_DETECTION</span><span class='embexpr_end'>}</span><span class='tstring_end'>`</span></span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_system_locale_posix'>system_locale_posix</span>
    <span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>LANG</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
  <span class='kw'>end</span>

  <span class='comment'># :nodoc:
</span>  <span class='kw'>def</span> <span class='id identifier rubyid_setup_backend'>setup_backend</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_load_path'>load_path</span> <span class='op'>+=</span> <span class='const'>Dir</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='ivar'>@path</span><span class='embexpr_end'>}</span><span class='tstring_content'>/*.yml</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_load_path'>load_path</span><span class='period'>.</span><span class='id identifier rubyid_uniq!'>uniq!</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_exception_handler'>exception_handler</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Exceptions</span><span class='op'>::</span><span class='const'>TranslationExceptionHandler</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
    <span class='id identifier rubyid_reload'>reload</span>

    <span class='ivar'>@backend</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_backend'>backend</span>
  <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>


  <div id="class_method_details" class="method_details_list">
    <h2>Class Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="instance-class_method">
  
    .<strong>instance</strong>(locale = nil, root: :lazier, path: nil, force: false)  &#x21d2; <tt><span class='object_link'><a href="" title="Lazier::I18n (class)">I18n</a></span></tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Returns the singleton instance of the settings.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>locale</span>
      
      
        <span class='type'>(<tt>Symbol|NilClass</tt>)</span>
      
      
        <em class="default">(defaults to: <tt>nil</tt>)</em>
      
      
        &mdash;
        <div class='inline'><p>The locale to use for translations. Default is the current system locale.</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>root</span>
      
      
        <span class='type'>(<tt>Symbol</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The root level of the translation.</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>path</span>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span>|NilClass</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The path where the translations are stored.</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>force</span>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="Boolean.html" title="Lazier::Boolean (module)">Boolean</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>Whether to force recreation of the instance.</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="" title="Lazier::I18n (class)">I18n</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The singleton instance of the i18n.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


31
32
33
34</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/lazier/i18n.rb', line 31</span>

<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='symbol'>:lazier</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>force:</span> <span class='kw'>false</span><span class='rparen'>)</span>
  <span class='ivar'>@instance</span> <span class='op'>=</span> <span class='kw'>nil</span> <span class='kw'>if</span> <span class='id identifier rubyid_force'>force</span>
  <span class='ivar'>@instance</span> <span class='op'>||=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='label'>root:</span> <span class='id identifier rubyid_root'>root</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="locales-instance_method">
  
    #<strong>locales</strong>  &#x21d2; <tt>Array</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Get the list of available translation for a locale.</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Array</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The list of available locales.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


78
79
80</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/lazier/i18n.rb', line 78</span>

<span class='kw'>def</span> <span class='id identifier rubyid_locales'>locales</span>
  <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_available_locales'>available_locales</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="reload-instance_method">
  
    #<strong>reload</strong>  &#x21d2; <tt><span class='object_link'><a href="Object.html" title="Lazier::Object (module)">Object</a></span></tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Reloads all the I18n translations.</p>


  </div>
</div>
<div class="tags">
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


53
54
55
56</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/lazier/i18n.rb', line 53</span>

<span class='kw'>def</span> <span class='id identifier rubyid_reload'>reload</span>
  <span class='comment'># Extract the backend to an attribute
</span>  <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_backend'>backend</span><span class='period'>.</span><span class='id identifier rubyid_load_translations'>load_translations</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="translate-instance_method">
  
    #<strong>translate</strong>(message, **args)  &#x21d2; <tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span></tt> 
  

  
    <span class="aliases">Also known as:
    <span class="names"><span id='t-instance_method'>t</span></span>
    </span>
  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Localize a message.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>message</span>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span>|Symbol</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The message to localize.</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>args</span>
      
      
        <span class='type'>(<tt>Array</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>Optional arguments to localize the message.</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The localized message.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


87
88
89
90
91
92
93
94
95
96</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/lazier/i18n.rb', line 87</span>

<span class='kw'>def</span> <span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
  <span class='comment'># PI: Ignore reek on this.
</span>  <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_root'>root</span><span class='embexpr_end'>}</span><span class='tstring_content'>.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>!~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^(\.|::)</span><span class='regexp_end'>/</span></span>

  <span class='kw'>begin</span>
    <span class='op'>::</span><span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='label'>raise:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='rparen'>)</span>
  <span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>I18n</span><span class='op'>::</span><span class='const'>MissingTranslationData</span>
    <span class='id identifier rubyid_raise'>raise</span> <span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Exceptions</span><span class='op'>::</span><span class='const'>MissingTranslation</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='rbracket'>]</span>
  <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="translate_in_locale-instance_method">
  
    #<strong>translate_in_locale</strong>(locale, message, *args)  &#x21d2; <tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span></tt> 
  

  
    <span class="aliases">Also known as:
    <span class="names"><span id='tl-instance_method'>tl</span></span>
    </span>
  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Localize a message in a specific locale.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>locale</span>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span>|Symbol</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The new locale to use for localization.</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>message</span>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span>|Symbol</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The message to localize.</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>args</span>
      
      
        <span class='type'>(<tt>Array</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>Optional arguments to localize the message.</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The localized message.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


105
106
107</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/lazier/i18n.rb', line 105</span>

<span class='kw'>def</span> <span class='id identifier rubyid_translate_in_locale'>translate_in_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_with_locale'>with_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_translate'>translate</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="translations-instance_method">
  
    #<strong>translations</strong>(locale = nil)  &#x21d2; <tt><span class='object_link'><a href="Hash.html" title="Lazier::Hash (module)">Hash</a></span></tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Gets the list of available translation for a locale.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>locale</span>
      
      
        <span class='type'>(<tt>Symbol|NilClass</tt>)</span>
      
      
        <em class="default">(defaults to: <tt>nil</tt>)</em>
      
      
        &mdash;
        <div class='inline'><p>The locale to list. Defaults to the current locale.</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="Hash.html" title="Lazier::Hash (module)">Hash</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The available translations for the specified locale.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


62
63
64
65</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/lazier/i18n.rb', line 62</span>

<span class='kw'>def</span> <span class='id identifier rubyid_translations'>translations</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_locale'>locale</span> <span class='op'>||=</span> <span class='ivar'>@locale</span>
  <span class='ivar'>@backend</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='symbol'>:translations</span><span class='rparen'>)</span><span class='lbracket'>[</span><span class='id identifier rubyid_locale'>locale</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="with_locale-instance_method">
  
    #<strong>with_locale</strong>(locale)  &#x21d2; <tt><span class='object_link'><a href="Object.html" title="Lazier::Object (module)">Object</a></span></tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Temporary sets a different locale and execute the given block.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>locale</span>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="String.html" title="Lazier::String (module)">String</a></span>|Symbol</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>The new locale to use for localization.</p>
</div>
      
    </li>
  
</ul>


</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


113
114
115
116
117
118
119
120
121
122</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/lazier/i18n.rb', line 113</span>

<span class='kw'>def</span> <span class='id identifier rubyid_with_locale'>with_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_locale'>locale</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_old_locale'>old_locale</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span>

  <span class='kw'>begin</span>
    <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_locale'>locale</span>
    <span class='kw'>return</span> <span class='kw'>yield</span>
  <span class='kw'>ensure</span>
    <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_locale'>locale</span> <span class='op'>=</span> <span class='id identifier rubyid_old_locale'>old_locale</span>
  <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

      <div id="footer">
  Generated on Thu Nov 10 11:39:24 2016 by
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.9.5 (ruby-2.3.0).
</div>

    </div>
  </body>
</html>