Module

LanguageHelpers

This file contains helpers for working with Languages in Linked.art

Author:
  • Adam Brin, Pamela Lam, Alyx Rossetti, Charles Webb, Selina Zawacki

View Source LanguageHelpers.js, line 1

Methods

# static doesObjectLanguageMatch(object, language, languageOptions) → {boolean}

Checks whether the object matches the language specified in it's language declaration

True cases:

  1. if language is undefined, return true
  2. if the language parameter matches the language of the object, return true
  3. if the language parameter doesn't match the language of the object the, but the
    languageOptions.fallbackLanguage parameter matches the language of the object, return true
  4. if the language of the object is not defined and languageOptions.includeItemsWithNoLanguage
    is true, return true
Parameters:
Name Type Description
object Object

the object to check for a matching language

language String

limits the results to just a specific language (or leave undefined to match all objects)

languageOptions Object

optional object with expected attributes

fallbackLanguage String

the language to use if the specified language is not found

includeItemsWithNoLanguage String

whether to include results with no language

lookupMap Object

a map of language names and IDs to use instead of the ISO 2-digit keys and AAT values

View Source LanguageHelpers.js, line 43

boolean
Examples
object without a 'language' attribute
doesObjectLanguageMatch({id:"1",content:"test"},"en") would return true
object without a 'language' attribute and with languageOptions.includeItemsWithNoLanguage == false
doesObjectLanguageMatch({id:"1",content:"test"},"en",{includeItemsWithNoLanguage:false}) would return false
with languageOptions.lookupMap
doesObjectLanguageMatch({id:"1",content:"test",language:"fr"},"en",{lookupMap:{fr: "en"}}) would return true
with languageOptions.fallbackLanguage
doesObjectLanguageMatch({id:"1",content:"test",language:"fr"},"en",{fallbackLanguage:'fr'}) would return true

# static getLanguageId(obj, languageOptions) → {Array}

Get the LanguageId(s) for a given object and returns the unique list of languages (normalized)

Parameters:
Name Type Description
obj Object

the object to look for the language block in

languageOptions Object

optional object with expected attributes

fallbackLanguage String

the language to use if the specified language is not found

includeItemsWithNoLanguage String

whether to include results with no language

lookupMap Object

a map of language names and IDs to use instead of the ISO 2-digit keys and AAT values

View Source LanguageHelpers.js, line 103

the unique list of languages represented in the data

Array
Examples
object with a string value in its 'language' attribute and no languageOptions
getLanguageId({language: 'en'}) would return "http://vocab.getty.edu/aat/300388277"
object with an object in its 'language' attribute and languageOptions.lookupMap defined
getLanguageId({language: {id: 'http://vocab.getty.edu/language/en'}}, {lookupMap: {'en': 'fr'}})
would return 'fr'
object without a 'language' attribute and languageOptions.lookupMap defined
getLanguageId({}, {lookupMap: {'en': 'fr'}}) would return "NO_LANGUAGE"

# static lookupAatFromIso(iso) → {String}

Looks up the AAT Language Code from the 2 letter ISO Code

Parameters:
Name Type Description
iso String

View Source LanguageHelpers.js, line 215

the full AAT URL

String

# static lookupIsoFromAat(id) → {String}

Looks up the ISO language code from the full AAT URL

Parameters:
Name Type Description
id String

View Source LanguageHelpers.js, line 194

the 2-letter iso code

String

# static normalizeLanguageId(lang_id, languageOptions) → {String}

Normalize a language id string to the corresponding AAT ID defined in the
aat.LANGUAGES or to something else defined by languageOptions.lookupMap

Algorithm summary:

  1. simplifies an AAT language code or other URL ending in ISO code (e.g. http://vocab.getty.edu/language/en)
    to just the ISO code (2 letter) (e.g. en) before checking for that code in the lookupMap.
  2. if the simplified lang_id param can't be found in the lookupMap, returns the original lang_id
Parameters:
Name Type Description
lang_id String

the language id to normalize

languageOptions Object

optional object with expected attributes

fallbackLanguage String

the language to use if the specified language is not found

includeItemsWithNoLanguage String

whether to include results with no language

lookupMap Object

a map of language names and IDs to use instead of the ISO 2-digit keys and AAT values

View Source LanguageHelpers.js, line 158

the normalized version of the language (by default, an AAT URL), or if no match,
reverts to the original lang_id parameter

String
Examples
AAT language code URL
normalizeLanguageId('http://vocab.getty.edu/language/en') would return "http://vocab.getty.edu/aat/300388277"
ISO code in aat.LANGUAGES
normalizeLanguageId('en') would return "http://vocab.getty.edu/aat/300388277"
ISO code in languageOptions.lookupMap
normalizeLanguageId('en', {lookupMap: {'el': 'greek'}}) would return "greek"