i18n support#121
Merged
vishalnarkhede merged 9 commits intomasterfrom Mar 31, 2020
Merged
Conversation
52db334 to
5065cb2
Compare
ef667ea to
f6bce30
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Streami18n - Wrapper around i18next class for Stream related translations.
API
constructor(options)
Contructor accepts following options:
language (String) default: 'en'
Language code e.g., en, tr
disableDateTimeTranslations (boolean) default: false
Disable translations for datetimes
debug (boolean) default: false
Enable debug mode in internal i18n class
logger (function) default: () => {}
Logger function to log warnings/errors from this class
dayjsLocaleConfigForLanguage (object) default: 'enConfig'
Config object for internal dayjs object, corresponding to language (param)
DateTimeParser (function)
Moment or Dayjs instance/function.
geti18Instance
Returns an instance of i18next used internally.
getAvailableLanguages
Returns all the languages (code) registered with Streami18n
getTranslations
Returns all the translations registered with Streami18n
getTranslators
Returns an object containing t (i18next translator) and momentjs instance (configured with set language)
registerTranslation
params
setLanguage
Set a different language
Instance of this class should be provided to StreamApp component to handle translations.
Stream provides following list of in-built translations:
Docs
Text translations
Simplest way to start using feed components in one of the in-built languages would be following:
If you would like to override certain keys in in-built translation.
UI will be automatically updated in this case.
If you would like to register additional languages, use registerTranslation. You can add as many languages as you want:
You can use the same function to add whole new language as well.
We have exported all the in-built translations in our library. You can import them in your project as following:
If you would like to maintain your own translation files:
the language-translations it contains e.g, If you are creating a translation file for Korean language then
ko.jsonDatetime translations
Stream react feeds components uses dayjs internally by default to format datetime stamp.
Dayjs has locale support as well - https://day.js.org/docs/en/i18n/i18n
Dayjs is a lightweight alternative to Momentjs with the same modern API.
Dayjs provides locale config for plenty of languages, you can check the whole list of locale configs at following url
https://github.com/iamkun/dayjs/tree/dev/src/locale
You can either provide the dayjs locale config while registering
language with Streami18n (either via constructor or registerTranslation()) OR you can provide your own Dayjs or Moment instance
to Streami18n constructor, which will be then used internally (using the language locale) in components.
e.g.,
Similarly, you can add locale config for dayjs while registering translation via
registerTranslationfunction.e.g.,
NOTE Please note here that locales in
dayjs/locale/it(and all other language locale files), does not load calendar relatedconfig like 'today at', 'tomorrow at' etc. You will need to manually configure calendar locale using updateLocale.
TIPS
you can set
disableDateTimeTranslationsto true.The default
enlocale config from dayjs is as follow:{ "months": [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], "monthsShort": [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ], "week": { "dow": 0, "doy": 6 }, "weekdays": [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ], "weekdaysMin": ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], "weekdaysShort": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], "calendar": { "sameDay": "[Today at] LT", "nextDay": "[Tomorrow at] LT", "nextWeek": "dddd [at] LT", "lastDay": "[Yesterday at] LT", "lastWeek": "[Last] dddd [at] LT", "sameElse": "L" }, "formats": { "LTS": "h:mm:ss A", "LT": "h:mm A", "L": "MM/DD/YYYY", "LL": "MMMM D, YYYY", "LLL": "MMMM D, YYYY h:mm A", "LLLL": "dddd, MMMM D, YYYY h:mm A" }, "invalidDate": "Invalid date", "ordinal": "%d.", "dayOfMonthOrdinalParse": /\\d{1,2}(th|st|nd|rd)/, "relativeTime": { "future": "in %s", "past": "%s ago", "s": "a few seconds", "ss": "%d seconds", "m": "a minute", "mm": "%d minutes", "h": "an hour", "hh": "%d hours", "d": "a day", "dd": "%d days", "M": "a month", "MM": "%d months", "y": "a year", "yy": "%d years" }, "meridiemParse": /[ap]\\.?m?\\.?/i, "abbr": "en" }