Skip to content

Is there a way to get a translation by string like in non typesafe i18n tools? #126

Answered by ivanhofer
m1212e asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, currently it is only possible to access the translations via an object-syntax. So each part has to be split on the '.' character. For dynamic attributes like the month, you need to use the [] syntax.
Your example looks right 👍
With dynamic values you could probably get type-errors so you will need to cast it. If item. month() returns a number but your translation will only contain values ranging from 1 - 12you will need to write it like this: LL.months[item.months() as any]().

Hope this answers your question.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@m1212e
Comment options

@ivanhofer
Comment options

@m1212e
Comment options

@ivanhofer
Comment options

Answer selected by m1212e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants