1.0.0 • Published 7 months ago

@l10nmonster/helpers v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

L10n Monster Basic Helpers

Sources

FS Source Adapter

this.source = new adapters.FsSource({
    globs: [ '**/values/strings.xml' ],
    filter: (resourceId) => (resourceId.indexOf('dont_translate.properties') === -1),
    targetLangs: [ 'it', 'ja' ],
    resDecorator: (resMeta) => (resMeta.resourceId.indexOf('DNT') === -1 ? resMeta : { ...resMeta, targetLangs: [] }),
});

An adapter that reads sources from the filesystem.

  • The globs array (mandatory) can specify wildcard patterns relative to the base directory where the l10nmonster.cjs is placed.
  • The optional filter function can further filter out what's returned by the glob patterns.
  • targetLangs is an array of languages to translate to
  • The optional resDecorator function can modify the resource metadata

Resource Filters

Filters are used to convert raw strings returned by sources into segments that are suitable for translation (ideally not too small that they can't be translated, and not too long that prevent translation reuse). They can be configured in content types as a single resourceFilter property.

ModuleExportDescription
helpersfilters.SnapFilterFilter for normalized resources in snap store.

Decoders

Decoders are used to convert strings with specific formats into either pure strings or placeholders. They can be configured in content types as a chain of decoders via the decoders property.

ModuleExportDescription
helpersnormalizers.namedDecoderGeneric wrapper to rename a decoder.
helpersnormalizers.doublePercentDecoderDecoder for %% escaping.
helpersnormalizers.bracePHDecoderDecoder for {param} style placeholders.
helpersnormalizers.keywordTranslatorMakerDecoder/encoder pair to protect/replace keywords.
helpersregex.decoderMaker(flag, regex, partDecoder)Internal utility to create decoders.
helpersxml.entityDecoderDecoder for XML entities.
helpersxml.CDataDecoderDecoder for XML CData.
helpersxml.tagDecoderDecoder for XML tags.

Encoders

Encoders are used to convert pure strings and placeholders back to their original format. They can be configured in content types as a chain of encoders via the textEncoders and codeEncoders properties.

ModuleExportDescription
helpersnormalizers.gatedEncoderGeneric flag-based encoder execution.
helpersnormalizers.doublePercentEncoderEncoder for %% escaping.
helpersregex.encoderMaker(name, regex, matchMap)Internal utility to create encoders.
helpersxml.entityEncoderEncoder for XML entities.

Targets

FS Target Adapter

this.target = new adapters.FsTarget({
    targetPath: (lang, resourceId) => resourceId.replace('values', `values-${lang}`),
});

An adapter that writes translated resources to the filesystem. It takes in the object constructor a targetPath function that given a language and the resource id of the source, it produces the target resource id.

Translation Providers

Translation providers are used to interface with the translation process.

ModuleExportAsyncSyncTranslationRefreshDescription
helperstranslators.GrandfatherCreate translations based on existing translated resources.
helperstranslators.RepetitionsCreate translations based on leverage of 100% text matches.
helperstranslators.VisicodePseudo-localization with visual identification of string id's.

Other

ModuleExportDescription
helpersutils.*Internal utilities. No stable interface. Use at your own risk.
helpersanalyzers.*Miscellaneous analyzers.
helpersstores.JsonJobStoreJob store based on JSON files in the filesystem.
helpersstores.FileBasedJobStoreAbstract job store based on JSON files in a blob store.
helpersstores.FsSnapStoreSnap store based on JSON files in the filesystem.
helpersstores.FileBasedSnapStoreAbstract snap store based on JSON files in a blob store.
helpersstores.FsStoreDelegateDelegate helper for FileBasedJobStore and FileBasedSnapStore to use the filesystem.
1.0.0

7 months ago