You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apps and plugins write the same parse and serialize pattern logic which can be abstracted with a function.
function parsePattern(value: string): Variant["pattern"] {
const pattern: Variant["pattern"] = []
// splits a pattern like "Hello {{name}}!" into an array of parts
// "hello {{name}}, how are you?" -> ["hello ", "{{name}}", ", how are you?"]
const parts = value.split(/(\{{.*?\}})/).filter((part) => part !== "")
for (const part of parts) {
// it's text
if ((part.startsWith("{{") && part.endsWith("}}")) === false) {
pattern.push({ type: "text", value: part })
}
// it's an expression (only supporting variables for now)
else {
const variableName = part.slice(1, -1)
pattern.push({ type: "expression", arg: { type: "variable-reference", name: variableName } })
}
}
return pattern
}
Proposal
Add a parsePattern and serializePattern function to the SDK to ease writing apps and plugins.
note that we previously thought that we need a serialized format to enable an abstracted parse/serialize pattern function. that's not true if we choose a function that take a config.
The text was updated successfully, but these errors were encountered:
Please account for spaces/empty chars in the variable definition scope with the regex. Additionally, it would be even safer/more robust if people can put in there whatever they want, including full sentences with special characters etc.
3. How does error detection, handling & propagation in case of not successfully parsed patterns look like?
Fallback to string. Users can fix the pattern themselves and apps have reduced complexity
i18next is able to reference other messages. Nice feature but no first class support from inlang. Instead of throwing, we can import the string as is. On export, i18next will reference the other message again.
Context
Apps and plugins write the same parse and serialize pattern logic which can be abstracted with a function.
Proposal
Add a
parsePattern
andserializePattern
function to the SDK to ease writing apps and plugins.Additional information
The text was updated successfully, but these errors were encountered: