{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-lang/gettext/issues/11","labels_url":"https://api.github.com/repos/elixir-lang/gettext/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/elixir-lang/gettext/issues/11/comments","events_url":"https://api.github.com/repos/elixir-lang/gettext/issues/11/events","html_url":"https://github.com/elixir-lang/gettext/issues/11","id":69208098,"number":11,"title":"Gettext public API","user":{"login":"josevalim","id":9582,"avatar_url":"https://avatars.githubusercontent.com/u/9582?v=3","gravatar_id":"","url":"https://api.github.com/users/josevalim","html_url":"https://github.com/josevalim","followers_url":"https://api.github.com/users/josevalim/followers","following_url":"https://api.github.com/users/josevalim/following{/other_user}","gists_url":"https://api.github.com/users/josevalim/gists{/gist_id}","starred_url":"https://api.github.com/users/josevalim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josevalim/subscriptions","organizations_url":"https://api.github.com/users/josevalim/orgs","repos_url":"https://api.github.com/users/josevalim/repos","events_url":"https://api.github.com/users/josevalim/events{/privacy}","received_events_url":"https://api.github.com/users/josevalim/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-04-17T20:09:55Z","updated_at":"2015-04-18T16:07:39Z","closed_at":null,"body":"For now all the work has been done on Gettext internals and it is time to discuss the public API. What I would like to call is this:\r\n\r\n    MyApp.Gettext.gettext \"hello world\"\r\n\r\nAnd this does a couple things:\r\n\r\n1. It is a macro because we want to collect those strings to automatically generate `.po` files. In order to be collected, the first argument needs to be a string at compilation time.\r\n\r\n2. The locale is implicit. Which means it needs to be stored in the process dictionary per gettext module. The key in the process dictionary can be the module itself, the default is `:en` but the default can be customized with the `:default_locale` option on `use`. What is the official gettext API for setting locale?\r\n\r\nHowever, this discussion brings one main question: what should be the API for doing dynamic lookups? \r\n\r\nOne option is to do the dynamic lookup still using the gettext macro:\r\n\r\n        string = \"this still works\"\r\n        MyApp.Gettext.gettext string\r\n\r\nAnd then, when generating the default `.po` file, we would warn on such usages so users remember of checking those strings into their `.po` files.\r\n\r\nAnother option though is to ask the users to go through the currently \"private\" `lgettext` function for doing the dynamic lookup. In doing such, they would need to explicitly pass the locale, domain and what not.\r\n\r\nThe third and final option is to introduce another set of functions that would be used for the dynamic lookup. Or even provide an API in the main Gettext module itself:\r\n\r\n      string = \"this still works\"\r\n      Gettext.gettext(MyApp.Gettext, string)\r\n\r\nThe rationale behind this last one is that for dynamic lookups the gettext module will likely be dynamic too, so provide an API that receives both is ok.\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/elixir-lang/gettext/issues/comments/94177239","html_url":"https://github.com/elixir-lang/gettext/issues/11#issuecomment-94177239","issue_url":"https://api.github.com/repos/elixir-lang/gettext/issues/11","id":94177239,"user":{"login":"ericmj","id":316890,"avatar_url":"https://avatars.githubusercontent.com/u/316890?v=3","gravatar_id":"","url":"https://api.github.com/users/ericmj","html_url":"https://github.com/ericmj","followers_url":"https://api.github.com/users/ericmj/followers","following_url":"https://api.github.com/users/ericmj/following{/other_user}","gists_url":"https://api.github.com/users/ericmj/gists{/gist_id}","starred_url":"https://api.github.com/users/ericmj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericmj/subscriptions","organizations_url":"https://api.github.com/users/ericmj/orgs","repos_url":"https://api.github.com/users/ericmj/repos","events_url":"https://api.github.com/users/ericmj/events{/privacy}","received_events_url":"https://api.github.com/users/ericmj/received_events","type":"User","site_admin":false},"created_at":"2015-04-18T16:07:39Z","updated_at":"2015-04-18T16:07:39Z","body":"> And then, when generating the default .po file, we would warn on such usages so users remember of checking those strings into their .po files.\r\n\r\nThis will be annoying because you would get the warning on every compilation even though it's perfectly valid code.\r\n\r\nI like the third approach best. Will users define their own `MyApp.Gettext` module, sort of like `Ecto.Repo`? If so they can always fall back to approach 2 from approach 3: `def my_gettext(string), do: Gettext.gettext(__MODULE__, string)`.\r\n\r\n> setlocale/1 doesn't really fit Elixir conventions though, so we need to choose between following gettext API or \"converting\" it to Elixir land. Thoughts?\r\n\r\nI had the same problem when creating Decimal. I was following a specification and had to convert the API to Elixir conventions. In Decimal I went around some of the global APIs (like setlocale/1) by using the process dict."}}