Skip to main content

i18n

info

This helper does not require @iiif/vault to work and the helpers can be used on any loaded Presentation 3 resource.

Some useful helpers for parsing language maps.

getValue()

Takes in a language map and returns the best fitting language based on the browser.

import { getValue, buildLocaleString } from '@iiif/vault-helpers/i18n';

// Simple utility.
const str1 = getValue(manifest.label); // string based on browser

buildLocaleString()

A helper that can be used to link to existing i18n libraries and implementations.

import { buildLocaleString } from '@iiif/vault-helpers/i18n';

const str2 = buildLocaleString(
manifest.label, // { en: ["Line 1", "Line 2"], none: ["Fallback"] }
'en-GB',
{
fallbacks: ['en-US', 'en'],
defaultText: 'Untitled manifest',
separator: '<br/>',
closest: false,
strictFallback: true,
}
); // => "Line 1<br/>Line 2"

getClosestLanguage()

Definition:

function getClosestLanguage(
i18nLanguage: string,
languages: string[],
i18nLanguages: string[] = [],
strictFallback = false
);

Example

import { getClosestLanguage } from '@iiif/vault-helpers/i18n';

// Simple utility.
const lang = getClosestLanguage(
'en-GB', // users current language
['en', 'cy', 'none'] // available languages in content
); // => en