support icu messageformat for translations
This commit is contained in:
parent
b5c514e1d1
commit
6d56f8b8aa
35 changed files with 839 additions and 104 deletions
33
build/intl-linter/utils/rule.ts
Normal file
33
build/intl-linter/utils/rule.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
|
||||
import { Location } from '@formatjs/icu-messageformat-parser';
|
||||
import type { Visitor } from './traverse';
|
||||
import { traverse } from './traverse';
|
||||
|
||||
export type Element = MessageFormatElement;
|
||||
export { Location };
|
||||
|
||||
export type Context = {
|
||||
messageId: string;
|
||||
report(message: string, location: Location | void): void;
|
||||
};
|
||||
|
||||
export type RuleFactory = {
|
||||
(context: Context): Visitor;
|
||||
};
|
||||
|
||||
export type Rule = {
|
||||
id: string;
|
||||
run(elements: Array<MessageFormatElement>, context: Context): void;
|
||||
};
|
||||
|
||||
export function rule(id: string, ruleFactory: RuleFactory): Rule {
|
||||
return {
|
||||
id,
|
||||
run(elements, context) {
|
||||
traverse(elements, ruleFactory(context));
|
||||
},
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue