go-playground / locales

:earth_americas: a set of locales generated from the CLDR Project which can be used independently or within an i18n package; these were built for use with, but not exclusive to https://github.com/go-playground/universal-translator
MIT License
270 stars 58 forks source link

Using runtime locale? #18

Open sharpner opened 6 years ago

sharpner commented 6 years ago

Is there a way to load locales based on a runtime variable?

I'd rather not import every package prior to knowing the locale. :)

deankarn commented 6 years ago

Hey @sharpner

I did use to have code generated that would accept the local string eg. en_US I did end up removing it however as having all the locales imported dramatically increases you're compile time and binary size; because the locale is found at runtime that means ALL locales will be compiled and included in your binary, even if you only use one.

however I have had a few people ask about it, so as long as the tradeoffs aren't a big deal I'll add it back next time I regenerate.

sharpner commented 6 years ago

I understand. Thanks for keeping it in mind :)

bep commented 3 years ago

https://github.com/bep/gotranslators