react-intl#MessageFormatElement TypeScript Examples
The following examples show how to use
react-intl#MessageFormatElement.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageFormatEditor.tsx From project-loved-web with MIT License | 6 votes |
function addRanges(ranges: Range[], path: Path, elements: MessageFormatElement[]): void {
for (const element of elements) {
ranges.push({
anchor: { path, offset: element.location!.start.offset },
focus: { path, offset: element.location!.end.offset },
type: element.type,
} as Range);
if (element.type === TYPE.select || element.type === TYPE.plural) {
for (const option of Object.values(element.options)) {
addRanges(ranges, path, option.value);
}
}
if (element.type === TYPE.tag) {
addRanges(ranges, path, element.children);
}
}
}
Example #2
Source File: intl.tsx From project-loved-web with MIT License | 5 votes |
function loadMessages(locale: string): Record<string, MessageFormatElement[]> {
try {
return require(`./compiled-translations/${locale}.json`);
} catch {
return {};
}
}