Multilingualization(M17n) 対応モジュール
When::BasicTypes::M17n の実装のうち When::BasicTypes 内部で 定義すべきでない部分を切り出してモジュールとしている
When::Parts::Locale Module のグローバルな設定を行う
aliases : Hash
Locale の読み替えパターンを Hash で指定する
aliases の指定がない場合、aliases は Alias(モジュール定数)と解釈する
# File when/parts.rb, line 40
40: def setup(aliases=nil)
41: @aliases = aliases || Alias
42: end
文字列の連結
other : String or When::Toos::Locale
連結する文字列
returns : When::Toos::Locale
連結された文字列
# File when/parts.rb, line 226
226: def +(other)
227: labels = {}
228: case other
229: when Locale
230: (@labels.keys + other.labels.keys).uniq.each do |key|
231: labels[key] = Locale._hash_value(@labels, key) + Locale._hash_value(other.labels, key)
232: end
233: else
234: @labels.keys.each do |key|
235: labels[key] = Locale._hash_value(@labels, key) + other.to_s
236: end
237: end
238: return dup._copy({:labels=>labels, :label=>to_s + other.to_s})
239: end
文字列の一致
regexp : String or Regexp
マッチする正規表現
returns : nil or Integer
Integer - マッチした位置のindex(いずれかの locale でマッチが成功した場合)
nil - すべての locale でマッチに失敗した場合
# File when/parts.rb, line 210
210: def =~(regexp)
211: @keys.each do |key|
212: index = (@labels[key] =~ regexp)
213: return index if index
214: end
215: return nil
216: end
部分文字列
range : 範囲
String#[] と同様の指定方法で範囲を指定する
returns : When::Parts::Locale
指定範囲に対応した部分文字列
# File when/parts.rb, line 191
191: def [](range)
192: dup._copy({
193: :label => to_s[range],
194: :labels => @labels.keys.inject({}) {|l,k|
195: l[k] = @labels[k][range]
196: l
197: }
198: })
199: end
書式指定による文字列化
other : [Object]
文字列化する Object の Array
locale : [String]
文字列化を行う locale の指定(デフォルト : すべて)
returns : When::Toos::Locale
文字列化された Object
# File when/parts.rb, line 251
251: def _printf(other, locale=nil)
252: # 処理する配列
253: terms = other.kind_of?(Array) ? [self] + other : [self, other]
254:
255: # locale key の配列
256: if locale == []
257: keys = []
258: else
259: keys = terms.inject([]) {|k,t|
260: k += t.keys if t.kind_of?(Locale)
261: k
262: }.uniq
263: keys &= locale if locale
264: end
265: keys << nil
266:
267: # labels ハッシュ
268: labels = keys.inject({}) {|l,k|
269: l[k] = When::Coordinates::Pair._format(
270: (block_given? ? yield(k, *terms) : terms).map {|t|
271: t.kind_of?(Locale) ? t/k : t
272: }
273: )
274: l
275: }
276:
277: # 生成
278: dup._copy({
279: :label => labels.delete(nil),
280: :labels => labels
281: })
282: end
特定 locale に対応した文字列の取得
loc : String
locale の指定 ( lang[-|_]country.encode )
lang - 言語
country - 国(省略化)
encode - 文字コード(省略化)
returns : String
loc に対応した文字列
# File when/parts.rb, line 161
161: def name(loc='')
162: return to_s unless loc
163: lang, code = loc.split(/\./)
164: result = Locale._hash_value(@labels, loc)
165: return result if !code || @labels.member?(loc)
166: return result.encode(code)
167: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.