package
Mozilla tools for localization
npm install @mozilla/l10nGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 3 packages.
418.8 kB
Includes dependencies.
This is a library of JavaScript tools and utilities for working with localization files, primarily built for internal use at Mozilla.
It's being bootstrapped to fulfil the needs of the Pontoon frontend, and to match the behaviour of the Python moz.l10n library.
The data structures used by the library are defined by a JSON Schema.
The library currently supports the following message pattern formats:
android: Android string resourcesfluent: Fluent (without internal selectors)mf2: MessageFormat 2.0plain: Patterns without placeholders (used in multiple resource formats)properties: Java .properties fileswebext: WebExtensions (messages.json)xliff: XLIFF 1.2, including XCode customizationsThe tooling for android and xliff depends on DOMParser, XMLSerializer, and related classes
which are available in browser environments.
The parser for fluent depends on the @fluent/syntax package,
and the parser for mf2 depends on the messageformat package.
import { messagesEqual } from '@mozilla/l10n'function messagesEqual(a: Message, b: Message): booleanAre the messages a and b deeply equal?
Messages are not normalised for this comparison. All catchall keys are considered equal with each other, and declaration order is ignored.
import { normalizeMessage } from '@mozilla/l10n'function normalizeMessage(msg: Message): MessageDrop unused declarations, join adjacent literal elements, and drop empty literal elements.
Does not modify msg.
Objects and arrays in returned value are clones of objects in msg.
import { ParseError, parsePattern } from '@mozilla/l10n'function parsePattern(
format:
'android' | 'fluent' | 'mf2' | 'plain' | 'properties' | 'webext' | 'xliff',
src: string,
options?: ParseOptions
): Pattern
class ParseError extends Error {
range?: [number, number] // Set for fluent, mf2, and webext errors
}Parse the string representation of a single flat message pattern into a data structure (JSON Schema).
Pass in ParseOptions option bag with:
webextBaseMsg: required by webext for named placeholders.xliffIsXcode: when parsing XLIFF generated by Xcode.If onError is undefined, errors are thrown.
import { SerializeError, serializePattern } from '@mozilla/l10n'function serializePattern(
format:
'android' | 'fluent' | 'mf2' | 'plain' | 'properties' | 'webext' | 'xliff',
pattern: Pattern,
onError?: (error: SerializeError) => void
): string
class SerializeError extends Error {
pos?: number // Set for fluent, plain, properties, and webext errors
}Serialize the data representation of a single flat message pattern into a string
If onError is undefined, errors are thrown.
import type {
Message,
PatternMessage,
SelectMessage,
Pattern,
Expression,
Markup
} from '@mozilla/l10n'type Message = Pattern | PatternMessage | SelectMessage
type Pattern = (string | Expression | Markup)[]mythmon
mythmon@gmail.com
project-nimbus-publishing
project-nimbus-publishing@mozilla.com
gijs
gijskruitbosch@gmail.com
brizental
brizental@mozilla.com
aplacitelli
aplacitelli@mozilla.com
mozrhelmer
rhelmer@mozilla.com
knowtheory
ted@knowtheory.net
nbaumgardner
niklasbaumgardner@gmail.com
tigleym
tigleym@gmail.com
eemeli
eemeli@gmail.com
hmanilla
hmanilla+npm@mozilla.com
jdescottes-mozilla-npm
jdescottes+npm@mozilla.com
ahanot
ahanot+npm@mozilla.com
bgrant_mozilla
bgrant+npm@mozilla.com
mlifshin
mlifshin+npm@mozilla.com
llisi-moz
llisi+npm@mozilla.com
jdarcangelo-mozilla
jdarcangelo+npm@mozilla.com
nchevobbe
nchevobbe+npm@mozilla.com