Stele - Stele Awareness
Stele Aware
Statically known strings
The basis for modern i18n are what Stele calls statically known strings. A statically known string is a string where no run time information is required to know the entire contents of the sentence.
Here is an example of a statically known string:
const message = 'Hi there Ben!'
Here is an example of a not statically known string:
const message = 'Hi there ' + getName()
The process of making your application Stele Aware therefore is the process of converting your application to using only statically known strings.
What is run time vs compile time?
How could you know by looking at a line of code whether the whole string is statically known or not? This is a surprisingly difficult question to answer. Knowing the answer is buried in a knowledge of ASTs, but to keep it high level something is statically known to stele if it comprised only of:
JSX
- Literals
- String literal:
'Hi!'
- Number literal: 1
- String literal:
- Identifiers
myValue
- Identifiers are essentially variables.
- MemberExpressions
props.myValue
- MemberExpressions are essentially identifiers made of objects.
- Stele Components
Translate
The second argument to the translate function is more strict. It can only be comprised of a string literal which is an ICU string.