{"action":"created","issue":{"url":"https://api.github.com/repos/svenfuchs/i18n/issues/197","repository_url":"https://api.github.com/repos/svenfuchs/i18n","labels_url":"https://api.github.com/repos/svenfuchs/i18n/issues/197/labels{/name}","comments_url":"https://api.github.com/repos/svenfuchs/i18n/issues/197/comments","events_url":"https://api.github.com/repos/svenfuchs/i18n/issues/197/events","html_url":"https://github.com/svenfuchs/i18n/issues/197","id":12845412,"number":197,"title":"Invalid fallback when trailing separator exists in a key","user":{"login":"killthekitten","id":1201569,"avatar_url":"https://avatars.githubusercontent.com/u/1201569?v=3","gravatar_id":"","url":"https://api.github.com/users/killthekitten","html_url":"https://github.com/killthekitten","followers_url":"https://api.github.com/users/killthekitten/followers","following_url":"https://api.github.com/users/killthekitten/following{/other_user}","gists_url":"https://api.github.com/users/killthekitten/gists{/gist_id}","starred_url":"https://api.github.com/users/killthekitten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/killthekitten/subscriptions","organizations_url":"https://api.github.com/users/killthekitten/orgs","repos_url":"https://api.github.com/users/killthekitten/repos","events_url":"https://api.github.com/users/killthekitten/events{/privacy}","received_events_url":"https://api.github.com/users/killthekitten/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2013-04-05T13:33:28Z","updated_at":"2016-11-20T22:56:41Z","closed_at":null,"body":"To explain a problem, I wrote a simple helper, that displays translation for an object field `kind`:\n\n```\n# config/locales/ru.yml\n\nru:\n  node:\n    kinds:\n      first: \"Первый\"\n      second: \"Второй\"\n```\n\n```\n# app/helpers/nodes_helper.rb\n\nmodule NodesHelper\n  def node_kind(value)\n    t(\"node.kinds.#{value}\", default: 'blank')\n  end\nend\n```\n\nHere is what I expected:\n\n```\nnode_kind('first') # => \"Первый\"\nnode_kind(nil)     # => \"blank\"\n```\n\nAnd here is the real behavior:\n\n```\nnode_kind('first') # => \"Первый\"\nnode_kind(nil)     # => {:first=>\"Первый\", :second=>\"Второй\"}\n```\n\nLet's see, what happens behind the scenes. I18n has a `normalize_key` method:\n\n```\n# gem/lib/i18n.rb\n\ndef normalize_key(key, separator)\n  normalized_key_cache[separator][key] ||=\n    case key\n    when Array\n      key.map { |k| normalize_key(k, separator) }.flatten\n    else\n      keys = key.to_s.split(separator)\n      keys.delete('')\n      keys.map! { |k| k.to_sym }\n      keys\n    end\nend\n```\n\nWhen we pass `nil` as an argument to `node_kind`, here is what happens: \n1. It calls `t(\"node.kinds.#{nil}\")` (notice that key has trailing separator `\"node.kinds.\"` in this case).\n2. `normalize_key` splits `key.to_s` and throws out last element (a blank value, caused by trailing separator).\n3. It recognizes `node.kinds` locale entry and returns a hash.\n\nIs it the way the `normalize_key` method should behave? Or is it a bug?\n"},"comment":{"url":"https://api.github.com/repos/svenfuchs/i18n/issues/comments/261812852","html_url":"https://github.com/svenfuchs/i18n/issues/197#issuecomment-261812852","issue_url":"https://api.github.com/repos/svenfuchs/i18n/issues/197","id":261812852,"user":{"login":"radar","id":2687,"avatar_url":"https://avatars.githubusercontent.com/u/2687?v=3","gravatar_id":"","url":"https://api.github.com/users/radar","html_url":"https://github.com/radar","followers_url":"https://api.github.com/users/radar/followers","following_url":"https://api.github.com/users/radar/following{/other_user}","gists_url":"https://api.github.com/users/radar/gists{/gist_id}","starred_url":"https://api.github.com/users/radar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/radar/subscriptions","organizations_url":"https://api.github.com/users/radar/orgs","repos_url":"https://api.github.com/users/radar/repos","events_url":"https://api.github.com/users/radar/events{/privacy}","received_events_url":"https://api.github.com/users/radar/received_events","type":"User","site_admin":false},"created_at":"2016-11-20T22:56:41Z","updated_at":"2016-11-20T22:56:41Z","body":"I agree with @tigrish's assessment of this issue."}}
{"actor":{"display_login":"radar"}}