Methods

Included Modules

Class Index [+]

Quicksearch

When::BasicTypes::M17n

多言語対応文字列

  本ライブラリで用いる諸々の用語を多言語対応で曖昧性なく管理するため
  Code の subclass として定義する

内部変数

self[ 0..-1 ] : String

 インスタンスを代表する文字列
 通常の String として振舞う場合は、この文字列として振舞う

@locale : Hash

 インスタンスがさす言葉の諸言語での表現を文字列として保持する
 locale指定('lang_country.encoding') => その locale での文字列
   locale指定の要素に省略がある場合、残った共通の要素によって文字列を特定する
   Ex. @locale = {'en'=>'March', 'ja'=>'三月'} ならば、locale が
       'en_US', 'en_GB' のいずれでもlocale での文字列は 'March'

@namespace : Hash

 インスタンスがさす言葉の意味を特定するための authority の URI を保持する
 locale指定('lang_country.encoding') => その locale での authority の URI
   locale指定の要素に省略がある場合、残った共通の要素によってURIを特定する
   Ex. @locale = {'en'=>'en:March', 'ja'=>'ja:3%E6%9C%88'} ならば、locale が
       'en_US', 'en_GB' のいずれでもlocale での authority の URIは 'en:March'
 当該用語が標準管理機関で管理されていない場合、wikipedia の当該項目の URI を用いる

@code_space : String

 代表的な authority の URI
  @namespace[''] である

see When::Parts::Locale, When::Parts::IRI

Public Class Methods

new(*args) click to toggle source

オブジェクトの生成

  labels : [String]
    String - '*locale:label=prefix:link'
      *       * 存在すれば、label をインスタンスを代表する文字列とする
      locale  - label に対応する locale指定(なければ、locale 引数の指定を用いる)
      label   - locale 指定に対応する label
      prefix:link - その locale での authority の URI
      prefix: - namespace 引数の指定により URI に展開する
      link    - なければ labelをURI encodeして用いる

  namespace : {prefix=>uri}
    lables, locale 引数の prefix の展開に用いる

  locale : [String]
    String - '*locale=prefix:link'
      *       * 存在すれば、label をインスタンスを代表する文字列とする
      locale  - locale指定
      prefix:link - authority の URI
      prefix: - namespace 引数の指定により URI に展開する

  Ex. M17n.new(['3月', 'fr:Mars=http://fr.wikipedia.org/wiki/Mars_(mois)', 'March'],
               {'en_wikipedia'=>'http://en.wikipedia.org/wiki/',
                'ja_wikipedia'=>'http://ja.wikipedia.org/wiki/'},
               ['=ja_wikipedia:', '*en=en_wikipedia:']) を行うと、生成された M17n では、
      @labels    = {''  =>'3月', 'fr'=>'Mars', 'en'=>'March'}
      @namespace = {''  =>'http://ja.wikipedia.org/wiki/3%E6%9C%88',
                    'fr'=>'http://fr.wikipedia.org/wiki/Mars_(mois)',
                    'en'=>'http://en.wikipedia.org/wiki/March'}
      となり、通常の String として振舞う場合は 'March' として振舞う
     # File when/basictypes.rb, line 424
424:       def initialize(*args)
425:         rest, options = _attributes(args)
426:         _sequence
427: 
428:         if (_pool[@label])
429:           _copy_all(_pool[@label])
430: 
431:         else
432:           if (rest)
433:             labels, namespace, locale = args
434:             @labels      = labels if labels
435:             @namespace ||= Parts::Locale._namespace(namespace) if namespace
436:             @locale    ||= Parts::Locale._locale(locale)       if locale
437:           end
438:           @namespace ||= {}
439:           @locale    ||= []
440: 
441:           @code_space  = @namespace['']
442:           self[0..1] = _labels(@labels, @namespace, @locale)
443:         end
444:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.