{"id":3539,"date":"2013-12-10T09:00:34","date_gmt":"2013-12-10T00:00:34","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=3539"},"modified":"2018-11-14T16:33:53","modified_gmt":"2018-11-14T07:33:53","slug":"thread-safe-options-in-i18n","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2013\/12\/10\/thread-safe-options-in-i18n\/","title":{"rendered":"I18n \u306b\u898b\u308b\u8907\u6570\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306b\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>Rails \u3067\u30ea\u30af\u30a8\u30b9\u30c8\u3054\u3068\u306b\u30ed\u30b1\u30fc\u30eb\u3092\u5909\u66f4\u3059\u308b\u306b\u306f\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u3054\u3068\u306b (before_action \u306a\u3069\u3067) I18n.locale \u306b :ja \u3084 :en \u306a\u3069\u3092\u4ee3\u5165\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>I18n \u3063\u3066\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\uff1f<\/h2>\n<p>\u5148\u65e5\u3001\u300cRails4 \u306e\u30ed\u30b1\u30fc\u30eb\u3063\u3066\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u3060\u3088\u306d\uff1f\u300d\u300c\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306b\u306a\u3063\u305f\u304b\u3089\u5927\u4e08\u592b\u306a\u306f\u305a\u3060\u3088\u306d\uff1f\u300d\u3068\u3044\u3046\u8a71\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u7d50\u8ad6\u304b\u3089\u8a00\u3046\u3068\u3001I18n \u306f\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306b\u4f5c\u3089\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306b\u3059\u308b\u306b\u306f\uff1f<\/h2>\n<p>\u305d\u3082\u305d\u3082 Ruby \u3067\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306a\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3068\u304d\u306b\u3084\u308b\u3079\u304d\u3053\u3068\u3092\u632f\u308a\u8fd4\u3063\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306b\u3059\u308b\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3044\u305a\u308c\u304b\u306e\u65b9\u6cd5\u3092\u3068\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u8907\u6570\u30b9\u30ec\u30c3\u30c9\u3067\u5171\u6709\u3059\u308b\u30ea\u30bd\u30fc\u30b9\u306b\u5bfe\u3057\u3066 Mutex\u00a0 \u3067\u4fdd\u8b77\u3059\u308b\u3002<\/li>\n<li>\u30b9\u30ec\u30c3\u30c9\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3092\u7528\u3044\u3066\u3001\u30b9\u30ec\u30c3\u30c9\u9593\u3067\u30ea\u30bd\u30fc\u30b9\u3092\u5171\u6709\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>I18n \u306e\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306a\u5b9f\u88c5<\/h2>\n<p>\u6c17\u306b\u306a\u3063\u305f\u306e\u3067 I18n \u306e<a href=\"https:\/\/github.com\/svenfuchs\/i18n\/blob\/v0.6.5\/lib\/i18n.rb#L17\">\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/a>\u3092\u8aad\u3093\u3067\u307f\u308b\u3068\u3001\u3053\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"lang:ruby decode:true\">    def config\r\n      Thread.current[:i18n_config] ||= I18n::Config.new\r\n    end\r\n\r\n    # Sets I18n configuration object.\r\n    def config=(value)\r\n      Thread.current[:i18n_config] = value\r\n    end<\/pre>\n<p>Confin \u3068\u3044\u3046\u30af\u30e9\u30b9\u304c I18n \u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4fdd\u6301\u3059\u308b\u5f79\u5272\u3092\u3057\u3066\u304a\u308a\u3001\u305d\u308c\u304c\u30b9\u30ec\u30c3\u30c9\u3054\u3068\u306b\u4fdd\u6301\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001I18n.locale \u306a\u3069\u306e\u30af\u30e9\u30b9\u30e1\u30bd\u30c3\u30c9\u306f\u6b21\u306e\u3088\u3046\u306b\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"lang:ruby decode:true\">    %w(locale backend default_locale available_locales default_separator\r\n      exception_handler load_path).each do |method|\r\n      module_eval &lt;&lt;-DELEGATORS, __FILE__, __LINE__ + 1\r\n        def #{method}\r\n          config.#{method}\r\n        end\r\n\r\n        def #{method}=(value)\r\n          config.#{method} = (value)\r\n        end\r\n      DELEGATORS\r\n    end<\/pre>\n<p>\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306b\u99b4\u67d3\u307f\u306e\u306a\u3044\u65b9\u306b\u306f\u5206\u304b\u308a\u3065\u3089\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001%w(locale backend ... load_path) \u306e\u305d\u308c\u305e\u308c\u306b\u3064\u3044\u3066\u3001config \u304b\u3089\u5024\u306e\u53d6\u5f97\/\u8a2d\u5b9a\u3092\u884c\u3046\u30a2\u30af\u30bb\u30c3\u30b5\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>Config \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u30b9\u30ec\u30c3\u30c9\u3054\u3068\u306b\u4fdd\u6301\u3059\u308b\u3088\u3046\u306b\u3057\u3064\u3064\u3001\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u30a2\u30af\u30bb\u30c3\u30b5\u3092\u307e\u3068\u3081\u3066\u5b9a\u7fa9\u3059\u308b\u3001\u3068\u3044\u3046\u624b\u6cd5\u3067\u3059\u3002<\/p>\n<p>Ruby \u3067\u306f\u3053\u306e\u3088\u3046\u306a\u5b9f\u88c5\u3092\u7c21\u5358\u306b\u5b9f\u73fe\u3067\u304d\u3066\u826f\u3044\u3067\u3059\u306d\uff08\uff3e\uff3e<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>Rails \u3067\u30ea\u30af\u30a8\u30b9\u30c8\u3054\u3068\u306b\u30ed\u30b1\u30fc\u30eb\u3092\u5909\u66f4\u3059\u308b\u306b\u306f\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u3054\u3068\u306b (before_action \u306a\u3069\u3067) I18n.locale \u306b :ja \u3084 :en \u306a\u3069\u3092\u4ee3\u5165\u3057\u307e\u3059\u3002<br \/><a href=\"https:\/\/www.techscore.com\/blog\/2013\/12\/10\/thread-safe-options-in-i18n\/\">\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[22,24,118,61,117],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/3539"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=3539"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/3539\/revisions"}],"predecessor-version":[{"id":17898,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/3539\/revisions\/17898"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=3539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=3539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=3539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}