Open pyladune opened 7 years ago
You don't need to pass all the model, just the language and the string ID.
Yes, but how to access to currentlanguage directly from utils.elm instead to pass it at each call of translate ? that would make the whole thing easier i think
On 11/04/2016 10:24 AM, Amitai Burstein wrote:
You don't need to pass all the model, just the language and the string ID.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Gizra/elm-i18n-example/issues/1#issuecomment-258380568, or mute the thread https://github.com/notifications/unsubscribe-auth/AB90fsbgSAUzBO3uGHaN7iDuCFONe4__ks5q6vnSgaJpZM4KpPUx.
You can't, because in Elm you always pass arguments around. No global state.
On Nov 4, 2016 11:44 AM, "Seb" notifications@github.com wrote:
Yes, but how to access to currentlanguage directly from utils.elm instead to pass it at each call of translate ? that would make the whole thing easier i think
On 11/04/2016 10:24 AM, Amitai Burstein wrote:
You don't need to pass all the model, just the language and the string ID.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Gizra/elm-i18n-example/issues/1# issuecomment-258380568, or mute the thread https://github.com/notifications/unsubscribe-auth/ AB90fsbgSAUzBO3uGHaN7iDuCFONe4__ks5q6vnSgaJpZM4KpPUx.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Gizra/elm-i18n-example/issues/1#issuecomment-258384722, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHrC9cttTbUs_zzEqnzug1ee20Ixo8Mks5q6v6GgaJpZM4KpPUx .
One way to just pass the string ID to the translate function would be to curry it beforehand, and then you can pass the curried translate function down to the submodule where you need it.
@simonewebdesign could you explain more or illustrate, seems interresting but don't get it at all :-)
@pyladune The translate function has this signature:
translate : Language -> TranslationId -> String
Curried:
curriedTranslate : TranslationId -> String
curriedTranslate trans =
translate currentLanguage trans
currentLanguage : Language
currentLanguage =
Japanese
At this point you can just use it anywhere without carrying the currentLanguage about :)
This implementation is pretty nice but would there be a as nice way to detect the language selected by user inside the utils functions ? The point is to be able to use translate function in submodule without passing the main model each time just for that