-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expose parsePattern
and serializePattern
#212
Comments
Cool!
|
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.
|
Holding off an implementation because I am unsure how to implement parsing and serializing expressions in a generic way. Only variable references is easy but not enough. Ideas welcome! This is the pattern of an i18next message, for example. Splitting the pattern in parts could be done with "Some {{val, number(minimumFractionDigits: 2)}}"
|
The challenge relies in only passing const i18nextConfig = {
variablePattern: /\{\{(.*?)\}\}/g,
functionPattern: /^(\w+)\((.*)\)$/,
keyValueSeparator: ':', // i18next uses colons
variableFormat: (name, format) => `{{${name}${format ? ', ' + format : ''}}}`,
optionsFormat: (options) => {
return options
.map((option) => {
const [key, value] = Object.entries(option)[0];
return `${key}: ${value}`;
})
.join(', ');
},
formatFunction: (funcName, optionsString) => {
return optionsString ? `${funcName}(${optionsString})` : funcName;
},
}; |
Nice one, thanks. How can we simplify the API?
|
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: