A cross-target ICU MessageFormat subset runtime and catalog linter for MoonBit.
Dependencies
moon add Zhouz-z/moon_l10nmoon add Zhouz-z/moon_l10n@0.2.0///|
import {
"Zhouz-z/moon_l10n",
}///|
test {
let message = @moon_l10n.parse_message(
"{count, plural, one {# file} other {# files}}",
)
let values : Map[String, @moon_l10n.Argument] = {
"count": @moon_l10n.Number(2),
}
inspect(@moon_l10n.format(message, values, "en"), content="2 files")
}///|
test {
let english = @moon_l10n.Catalog::from_json(
"en", "{\"files\":\"{count, plural, one {# file} other {# files}}\"}",
)
let translator = @moon_l10n.Translator::new("zh-CN", "en")
translator.add_catalog(english)
let result = translator.translate_detailed(
"files",
{ "count": @moon_l10n.Number(1) },
locale="zh-Hans-CN",
)
inspect(result.value(), content="1 file")
inspect(result.resolved_locale(), content="en")
}Hello {name}{gender, select, female {She} male {He} other {They}}{count, plural, =0 {No files} one {# file} other {# files}}{position, selectordinal, one {#st} two {#nd} few {#rd} other {#th}}{
"greeting": "Hello {name}",
"files": "{count, plural, one {# file} other {# files}}"
}zh-Hans-CN -> zh-Hans -> zh -> configured default -> configured fallbackmoon run cmd/main -- validate examples/locales/en.json examples/locales/en.json en
moon run cmd/main -- validate examples/locales/en.json examples/locales/ru.json ru --jsonmoon run cmd/main -- diff examples/locales/en.json examples/locales/zh-CN.json zh-CNmoon run cmd/main -- render examples/locales/en.json en files count=3
moon run cmd/main -- render examples/locales/en.json en files count=1 --jsonpython scripts/count_effective_moonbit.py --minimum 4000
moon fmt --check
moon check --target all --deny-warn
moon build --target all --deny-warn
moon test --target all --deny-warn
moon info
moon packagepub(all) struct ArgumentUse {
name : String
roles : Array[ArgumentRole]
occurrences : Int
} derive(Eq, Debug)fn Catalog::merge(self : Catalog, other : Catalog, policy? : CatalogMergePolicy) -> Catalog raise MessageErrorfn Catalog::with_entry(self : Catalog, key : String, template : String) -> Catalog raise MessageErrorpub(all) struct CatalogEntryAnalysis {
key : String
template : String
valid : Bool
diagnostic : MessageDiagnostic?
message : MessageAnalysis?
} derive(Debug)pub(all) struct CatalogMatrix {
reference_locale : String
locales : Array[String]
rows : Array[CatalogMatrixRow]
} derive(Eq, Debug)pub(all) struct ChoiceUse {
argument : String
kind : ChoiceKind
selectors : Array[String]
depth : Int
ordinal : Int
} derive(Eq, Debug)pub(all) struct FormatEvent {
kind : FormatEventKind
depth : Int
path : String
argument : String?
selector : String?
output : String
} derive(Eq, Debug)pub(all) struct FormatOptions {
missing_argument : MissingArgumentBehavior
maximum_depth : Int
} derive(Eq, Debug)fn FormattedMessage::events_for_argument(self : FormattedMessage, argument : String) -> Array[FormatEvent]pub struct LintIssue {
severity : LintSeverity
code : String
key : String
message : String
argument : String?
selector : String?
} derive(Eq, Debug)pub(all) struct LocaleProfile {
locale : LocaleId
direction : TextDirection
cardinal_family : PluralRuleFamily
ordinal_family : PluralRuleFamily
cardinal_categories : Array[String]
ordinal_categories : Array[String]
} derive(Eq, Debug)pub(all) struct LocaleSupport {
language : String
english_name : String
native_name : String
direction : TextDirection
cardinal_categories : Array[String]
ordinal_categories : Array[String]
} derive(Eq, Debug)pub(all) struct MessageAnalysis {
arguments : Array[ArgumentUse]
node_count : Int
text_node_count : Int
argument_node_count : Int
choice_node_count : Int
pound_node_count : Int
maximum_depth : Int
} derive(Eq, Debug)pub(all) struct MessageDiagnostic {
code : String
message : String
position : SourcePosition
} derive(Eq, Debug)pub(all) enum MessageNode {
TextNode(String)
ArgumentNode(String)
PoundNode
ChoiceNode(String, String, Map[String, Array[MessageNode]])
} derive(Debug)fn MessageSignature::choices_for_argument(self : MessageSignature, name : String) -> Array[ChoiceUse]fn MessageSignature::choices_of_kind(self : MessageSignature, kind : ChoiceKind) -> Array[ChoiceUse]fn Translator::resolve(self : Translator, key : String, locale? : String) -> ResolvedMessage raise MessageErrorfn Translator::translate(self : Translator, key : String, arguments : Map[String, Argument], locale? : String) -> String raise MessageErrorfn Translator::translate_detailed(self : Translator, key : String, arguments : Map[String, Argument], locale? : String) -> TranslationResult raise MessageErrorfn cli_diff_sources(reference_source : String, translation_source : String, locale : String, json? : Bool) -> CliOutput raise MessageErrorfn cli_render_source(source : String, locale : String, key : String, arguments : Map[String, Argument], json? : Bool) -> CliOutput raise MessageErrorfn cli_validate_sources(reference_source : String, translation_source : String, locale : String, json? : Bool) -> CliOutput raise MessageErrorfn format(message : Message, arguments : Map[String, Argument], locale : String) -> String raise MessageErrorfn format_with_options(message : Message, arguments : Map[String, Argument], locale : String, options : FormatOptions) -> String raise MessageErrorfn format_with_trace(message : Message, arguments : Map[String, Argument], locale : String, options? : FormatOptions) -> FormattedMessage raise MessageErrorfn is_supported_locale(locale : String) -> Boolfn lint_catalogs_with_options(reference : Catalog, translation : Catalog, options : LintOptions) -> LintReportfn negotiate_locale(requested : String, available : Array[String], default_locale? : String) -> LocaleNegotiationfn observed_plural_categories(locale : String, start : Int, end : Int, ordinal? : Bool) -> Array[String]fn plural_examples(locale : String, start : Int, end : Int, ordinal? : Bool, limit_per_category? : Int) -> Array[PluralExamples]fn select_plural_branch(locale : String, value : Int, ordinal : Bool, selectors : Array[String]) -> PluralSelection raise MessageErrorA cross-target ICU MessageFormat subset runtime and catalog linter for MoonBit.
Dependencies