Coder Social home page Coder Social logo

gettexter's People

Contributors

seriyps avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gettexter's Issues

Possibility to avoid process dictionary

In a project I work with, we use a lot of processes and find it cumbersome to set the locale in each process.

I would like a version of each of the functions that take the locale explicitly to each function call as an extra parameter.

gettexter:dgettext(my_domain, "hello").       %% Current locale
gettexter:dgettext(my_domain, "hello", "en"). %% Explicit locale

gettexter:pngettext(Ctx, Str, StrPlural, N).       %% Current locale
gettexter:pngettext(Ctx, Str, StrPlural, N, "en"). %% Explicit locale

%% etc.

error with gettexter:setlocale

getting an error with gettexter:setlocale

** exception error: no match of right hand side value {error,{error,undef,
                                                                    [{erl_syntax,atom,[gettexter_plural],[]},
                                                                     {gettexter_plural,to_erlang_ast,2,
                                                                                       [{file,"src/gettexter_plural.erl"},{line,98}]},
                                                                     {gettexter_plural,to_erlang_abstract,2,
                                                                                       [{file,"src/gettexter_plural.erl"},{line,109}]},
                                                                     {gettexter_plural,compile,2,
                                                                                       [{file,"src/gettexter_plural.erl"},{line,78}]},
                                                                     {gettexter_server,load_plural_rule,4,
                                                                                       [{file,"src/gettexter_server.erl"},{line,172}]},
                                                                     {gettexter_server,load_locale,3,
                                                                                       [{file,"src/gettexter_server.erl"},{line,153}]},
                                                                     {gettexter_server,handle_call,3,
                                                                                       [{file,"src/gettexter_server.erl"},{line,101}]},
                                                                     {gen_server,handle_msg,5,
                                                                                 [{file,"gen_server.erl"},{line,588}]}]}}
     in function  gettexter:setlocale/2 (src/gettexter.erl, line 62)

Cannot get translated string

Hi everyone,

I am just trying this out and the ets:lookup returns undefined in gettexter_server:42 (while ets table of gettexter_server_ets is populated)

  gettexter:bindtextdomain(?GETTEXT_DOMAIN, "apps/web/priv/locale"),
  gettexter:textdomain(?GETTEXT_DOMAIN),
  gettexter:setlocale(lc_messages, "ru"),
  ?_("Wanna sleep?")
ets:tab2list(gettexter_server_ets).
[{{hdr,my_app,"ru",<<"x-generator">>},
  <<"Poedit 1.5.4">>},
 {{msg,my_app,"ru",undefined,<<"One other domain">>,
       <<"~p other domains">>,2},
  <<"~p других доменов"/utf8>>},
 {{msg,my_app,"ru",undefined,<<"Wanna sleep?">>,
       undefined,0},
  <<"Хочешь спать?"/utf8>>},
 {{binding,my_app},"apps/web/priv/locale"},
 {{msg,my_app,"ru",undefined,<<"go sleep a hour">>,
       <<"go sleep ~p hours">>,1},
  <<"сходи поспи ~p часа"/utf8>>},
 {{hdr,my_app,"ru",<<"po-revision-date">>},
  <<"2014-02-26 05:40+0300">>},
 {{hdr,my_app,"ru",<<"report-msgid-bugs-to">>},<<>>},
 {{hdr,my_app,"ru",<<"language">>},<<"ru">>},
 {{hdr,my_app,"ru",<<"language-team">>},
  <<"Russian <[email protected]>">>},
 {{msg,my_app,"ru",undefined,<<"Wanna eat?">>,
       undefined,0},
  <<"Хочешь есть?"/utf8>>},
 {{msg,my_app,"ru",undefined,<<"One other domain">>,
       <<"~p other domains">>,1},
  <<"~p других домена"/utf8>>},
 {{hdr,my_app,"ru",<<"pot-creation-date">>},
  <<"2014-02-21 01:34+0400">>},
 {{hdr,my_app,"ru",<<"content-transfer-encoding">>},
  <<"8bit">>}, 
 {{msg,my_app,"ru",undefined,<<"Hello, ~p! ~ts">>,
       undefined,0},
  <<"Привет, ~p! ~ts"/utf8>>},
 {{msg,my_app,"ru",<<"the-context">>,
       <<"One other domain">>,
       <<"~p other domains">>,0},
  <<"~p другой домен"/utf8>>},
 {{msg,my_app,"ru",undefined,<<"go sleep a hour">>,
       <<"go sleep ~p hours">>,0},
  <<"сходи поспи ~p час"/utf8>>},
 {{loaded,my_app,"ru"},
  "................../apps/web/priv/locale/ru/LC_MESSAGES/my_app.mo"},
 {{hdr,my_app,"ru",<<"plural-forms">>},
  <<"nplurals=3; plural=(n%10==1 && n%100"...>>},
 {{msg,my_app,"ru",undefined,<<"take one babana">>,
       <<"take ~p bana"...>>,2},
  <<"возьми ~p бананов"/utf8>>},
 {{msg,my_app,"ru",undefined,<<"So, you may "...>>,
       undefined,0},
  <<"Итак, ты говоришь ~ts"/utf8>>},
 {{hdr,my_app,"ru",<<"content-type">>},
  <<"text/plain; charset=UTF-"...>>},
 {{hdr,my_app,"ru",<<"last-tra"...>>},
  <<"Sergey Prokhorov <me"...>>},
 {{msg,my_app,"ru",<<"the-"...>>,<<...>>,...},
  <<"~p других домено"/utf8...>>},
 {{msg,my_app,"ru",undefined,...},
  <<"возьми ~p ба"/utf8...>>},
 {{hdr,my_app,[...],...},<<"1.0">>},
 {{msg,my_app,...},<<"возь"/utf8...>>},
 {{msg,...},<<...>>},
 {{...},...},
 {...}|...]

(using ru translation from test) .po file has been compiled to .mo as well.

What step am I missing?

Cheers!
Erwin

Test file doesn't work with the current code of gettexter.erl

gettexter:setlocale(undefined, "ru"),
gettexter:textdomain(?GETTEXT_DOMAIN),

should be

gettexter:textdomain(?GETTEXT_DOMAIN),
gettexter:setlocale(lc_messages, "ru"),

as setlocale fails unless textdomain is set ( true = (TextDomain =/= undefined), ) and the Category must be lc_messages ( setlocale(Category=lc_messages, Locale) ->).

Binaries

Possibility to use binaries in original and translated strings.

I suggest using the same macros and functions, but if the original is binary, you get the translation as a binary as well. If you strings, you'll get a string for the translation. This would be backwards compatible.

?_(<<"my binary string">>)

Parse transform for extracting strings

The other gettext repo https://github.com/etnt/gettext has a parse transform for extracting strings (i.e. the job of xgettext). This could be more or less easily ported to gettexter. Then, it would be fairly easy to add support for binaries ?_(<<"foo">>) and handle Erlang-specific string syntax better than xgettext, s.t. adjacent string literals ?_("string" "42") and odd Erlang-specific escape sequences ?_("\x{128525}") (the 😍 symbol).

We are willing to implement this. Hopefully you'll be interested to merge a pull request in the following days or weeks....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.