Comments (20)
I think we already have those they are just not exposed (but you probably knew that).
from gettext.
This is also kind of a "natural" function to have as internally other functions would still be built on it, e.g.:
defmodule Gettext do
def gettext(backend, msgid, bindings \\ %{}) do
backend.lgettext(get_locale(backend), msgid, bindings)
end
end
would become just
defmodule Gettext do
def gettext(backend, msgid, bindings) do
gettext(backend, get_locale(locale), msgid, bindings)
end
end
(roughly ofc)
The only nasty thing I foresee (but which is an implementation detail) is that arities will start clashing, e.g., gettext(backend, locale, msgid)
vs gettext(backend, msgid, bindings)
.
from gettext.
@josevalim yes we have them as l*gettext
in the backends, but we don't expose them in the backend or in Gettext
.
from gettext.
@whatyouhide right. I would consider exposing them instead so we avoid the argument issue.
from gettext.
@josevalim expose the l*gettext
functions in the backends you mean? What about macros, should they support specifying a locale as well?
from gettext.
@whatyouhide because it is meant to be dynamic, no need to have them in the backend only on Gettext?
from gettext.
The locale is meant to be dynamic but the msgids not necessarily, right? I mean in our use case we would call:
MyApp.Gettext.lgettext(user_locale, "This guy scored a goal!")
and still use mix gettext.extract
.
from gettext.
@whatyouhide good call, yes.
from gettext.
@josevalim so the thing will be that it will be nasty to generate private and internal l*gettext/*
functions and l*gettext/*
public macros in a backend IMO. What I would do is rename the internal functions to something like compiled_gettext
and compiled_ngettext
and introduce the public macros lgettext
, lngettext
, ldgettext
, ldngettext
(jeez these names are horrible btw, ldngettext
is a mouthful). Wdyt?
from gettext.
@whatyouhide another option is to allow it only through Gettext and in the dynamic format... or just accept Gettext.with_locale is the way to go because of the API complexity.
from gettext.
@josevalim the thing is that as I said above I think it would be pretty legit to use lgettext
with a compile-time string that you then want extracted by gettext.extract
😕 As for the with_locale
, the problem is that it's indeed quite slower I think because we need to set some app env, retrieve it to translate, and set it back after. But I agree on the complexity that the API would gain so I'm not sure what a good solution would be. Thoughts @lexmag?
from gettext.
Don't we use the process dictionary?
from gettext.
Correct, sorry, I meant the pdict :)
from gettext.
Yeah, I think neither with_locale
(besides pdict dance there is anonymous function creation) nor dynamic functions are good options, it feels to me a nice solution to try in that comment: #112 (comment).
Otherwise we would need to fork Gettext and adjust it to our needs. 😞
from gettext.
Have you measured? Because storing to pdict and a anonymous function sounds
really really minor, specially because you are going over the network for
push notifications anyway?
On Monday, July 25, 2016, Aleksei Magusev [email protected] wrote:
Yeah, I think neither with_locale (besides pdict dance there is anonymous
function creation) nor dynamic functions are good options, it feels to me a
nice solution to try in that comment: #112 (comment)
#112 (comment)
.
Otherwise we would need to fork Gettext and adjust it to our needs. 😞—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#112 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAlbjHdfEq81kSDuaM7RpCOU96YxBd0ks5qZJKlgaJpZM4JRusM
.
José Valimwww.plataformatec.com.br
http://www.plataformatec.com.br/Founder and Director of R&D
from gettext.
Yes, indeed it's tiny difference for a single call, but not having anonymous function creation it makes payload generating about 2 times faster, for 1 million recipients – translation calls take 0,09s instead of 0,15s.
It may do some greater difference when several push events happening at the same time, also there is unnecessary garbage.
That said, not sure this justifies the change (at lest we don't need to fork, not today ). ¯_(ツ)_/¯
from gettext.
I'm torn a bit on this. On one hand, these macros seem really natural to have and they also bring improvements in terms of speed (slight) and garbage (with the anon function, this could get nastier than speed). However, on the other hand, we had no other users requesting this, which makes me think it's not a features many want; note that this may just be because users are ok with with_locale/2
and are not too worried (either because they don't know or don't care) about pdict or anonymous functions.
What do you suggest we do here? :)
from gettext.
In your case, can't you just set the locale without with_locale? What is
the point of wrapping in function if you are changing it in the next item
anyway?
On Monday, July 25, 2016, Andrea Leopardi [email protected] wrote:
I'm torn a bit on this. On one hand, these macros seem really natural to
have and they also bring improvements in terms of speed (slight) and
garbage (with the anon function, this could get nastier than speed).
However, on the other hand, we had no other users requesting this, which
makes me think it's not a features many want; note that this may just be
because users are ok with with_locale/2 and are not too worried (either
because they don't know or don't care) about pdict or anonymous functions.What do you suggest we do here? :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#112 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAlbj3_7pG-EpzEfkEDIkJy6EY_j_sKks5qZQE2gaJpZM4JRusM
.
José Valimwww.plataformatec.com.br
http://www.plataformatec.com.br/Founder and Director of R&D
from gettext.
We probably can and likely will do (don't really remember why we didn't do it from the beginning), anyway, I think these new locale functions can wait. 💛
from gettext.
Awesome, let's wait if other users request this, especially now that they may see this issue. Thanks everybody for the help 💟
from gettext.
Related Issues (20)
- check-up-to-date fails even though files are just extracted HOT 8
- Flaky test in `gettext.extract`
- Duplicate Filename in Reference when `:write_reference_line_numbers` is set to `false`
- Gettext.PluralFormError for plural form "1" in "ja" locale HOT 9
- `gettext.merge` FunctionClauseError HOT 4
- Module is not loaded because :nofile HOT 4
- Mention file path in plural forms deprecation warning HOT 4
- Plural Forms warning occurs in newly generated language file HOT 2
- bump a new version for #359 HOT 1
- Duplicate msgid with singular and plural form HOT 5
- Running `mix gettext.extract` doesn't extract new messages with Elixir 1.15 HOT 2
- Retain custom flags during merge HOT 3
- Interpolation option set but not working HOT 4
- Duplicate references in POT files and warnings about redefining modules HOT 5
- compile depend excoveralls - origin/httpc failed HOT 1
- Add `Gettext.example` macro HOT 6
- If changes to `.po` file are discarded (accidentally), they're not added back HOT 17
- Allow to transform messages at compile time HOT 3
- `expo.msguniq` merges translations with different plurals HOT 4
- Locale changes between static mount and liveview HOT 1
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 gettext.