Comments (6)
https://github.com/ruby-i18n/i18n
from bcdice.
ruby-i18nは全てがモジュールで管理されており、ロケールをモジュールの特異メソッドで指定することでロケールを変更する。
一つのアプリケーションで複数のロケールを同時に扱いたいことを加味すると、BCDiceで利用するのは適切でないように思える。
from bcdice.
ruby-i18nは全てがモジュールで管理されており、ロケールをモジュールの特異メソッドで指定することでロケールを変更する。
それでは対応できない場合もあることから、I18n.locale
では、キーワード引数 locale:
でロケールを明示できます。
from bcdice.
いちいちロケールを指定するのは正直面倒なので、wapperメソッドを作ればいけそうですかね
from bcdice.
いちいちロケールを指定するのは正直面倒なので、wapperメソッドを作ればいけそうですかね
ですね。Railsのコントローラ/ビュー風だと、例えばこんな雰囲気になりそうです。
class DiceBot
# @return [Symbol]
attr_accessor :lang
private
# t('karidice.nanika') のように使える
def t(key, **options)
options_with_locale = { locale: @lang }.merge(options)
I18n.translate(key, **options_with_locale)
end
end
from bcdice.
メモ
以下のようにしてYAMLの内部構造を配列にしても、配列のまま取り出せる。
途中のkeyを取り出すと、Hashが帰ってくる
jp_ja:
ほげ表:
name: 'ホゲ今日'
rows: [
'hououin',
'shiina',
'hashida',
'makise',
]
require 'i18n'
I18n.load_path << Dir["./*.yaml"]
I18n.default_locale = :jp_ja
p I18n.t('ほげ表.rows') #=> ["hououin", "shiina", "hashida", "makise"]
p I18n.t('ほげ表') #=> {:name=>"ホゲ今日", :rows=>["hououin", "shiina", "hashida", "makise"]}
from bcdice.
Related Issues (20)
- ソード・ワールド系のi18n化
- ドラクルージュの抗い判定の改善
- Fate core system
- シノビガミのファンブル表が初期文庫版から改訂されている HOT 1
- [SwordWorld2.0] レーティング表部分の解析結果のリファクタリング
- [Cthulhu] RESの引数の挙動
- Proposal: Command::Parserの改善 HOT 2
- ビギニングアイドル新版の対応
- ゴブリンスレイヤーTRPGで大成功/大失敗の閾値を変数に
- 表類の誤植修正
- ワールドオブダークネスのバグ?
- エモクロアTRPGのi18n対応
- アリアンロッドRPGのi18n対応
- D66の並べ替え指定が小文字だと機能しない
- [CyberpunkRed] 判定が `>=` でなく `>`
- Codecovの移行
- スカイノーツ NEHの誤植
- エモクロアのヘルプメッセージを公式用語を使って整理する
- シノビガミのヘルプ誤植
- 『逆転計略TRPG 天才軍師になろう』の対応
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bcdice.