11/*
2- * Copyright 2019-2023 VMware, Inc.
2+ * Copyright 2019-2024 VMware, Inc.
33 * SPDX-License-Identifier: EPL-2.0
44 */
55import * as singletonCore from '@singleton-i18n/js-core-sdk' ;
66import { ENGLISH } from './source.l10n' ;
77import { config as defaultConfig } from './config' ;
88
99/**
10- * Should be executed in the html file that needs to be localized.
11- *
10+ * Should be executed in the html file that needs to be localized.
11+ *
1212 * @param {* } config object that provides the configuration with the following format
1313 * {
14- * productID, version, component, host, localizeAttribute, langCookieName, localStoragePseudoKey
15- * }
14+ * productID, version, component, host, localizeAttribute, langCookieName, localStoragePseudoKey
15+ * }
1616 */
1717export function localize ( config ) {
1818
1919 config = config ? config : { } ;
20- // If some properties aren't provided by the given config
20+ // If some properties aren't provided by the given config
2121 // we are getting them from the defaultConfig
2222 config = Object . assign ( defaultConfig , config ) ;
2323 const lang = detectLanguage ( config ) ;
@@ -39,16 +39,20 @@ export function localize(config) {
3939 language : lang ,
4040 sourceBundle : ENGLISH ,
4141 // Uncommend if you don't want to load your translation from singleton but from your sources
42- //i18nAssets: 'src/translations/',
42+ //i18nAssets: 'src/translations/',
4343 isPseudo : shouldUsePseudoTranslations ( ) ,
44+ // It offers the feature to self-custom header for target product
45+ httpOptions : {
46+ headers : { 'vrni-header' : 'vrni_custom' }
47+ }
4448 }
4549 ) ;
4650 loadAndShowTranslations ( i18nClient , config ) ;
4751}
4852
4953/**
50- * Collects all elements from the page that have the l10n attribute.
51- * Gets the attribute's value which is the key for the message, localizes the message
54+ * Collects all elements from the page that have the l10n attribute.
55+ * Gets the attribute's value which is the key for the message, localizes the message
5256 * and inserts it in the element.
5357 */
5458function loadAndShowTranslations ( i18nClient , config ) {
@@ -65,12 +69,12 @@ function loadAndShowTranslations(i18nClient, config) {
6569}
6670
6771/**
68- * Function that gets the current language.
69- * If not set in the cookies it tries to detect the browser's.
70- * If the browser's language isn't supported by singleton, falls back to english.
72+ * Function that gets the current language.
73+ * If not set in the cookies it tries to detect the browser's.
74+ * If the browser's language isn't supported by singleton, falls back to english.
7175 */
7276function detectLanguage ( config ) {
73- // First checks for lang in the cookie
77+ // First checks for lang in the cookie
7478 let language = getCookie ( config . langCookieName ) ;
7579 if ( language ) {
7680 return language ;
@@ -81,8 +85,8 @@ function detectLanguage(config) {
8185 return language || undefined ;
8286}
8387
84- /**
85- * Gets a cookie by its name.
88+ /**
89+ * Gets a cookie by its name.
8690 */
8791function getCookie ( name ) {
8892 function escape ( s ) { return s . replace ( / ( [ . * + ? \^ $ { } ( ) | \[ \] \/ \\ ] ) / g, '\\$1' ) ; } ;
0 commit comments