import Lang, { LangOptions } from 'lang.js';
import trans from '../../translations';

const userLang: string = document.documentElement.lang;
const langOpt: LangOptions = {
  fallback: 'de',
  locale: userLang,
  messages: trans
};
const lang = new Lang(langOpt);
lang.setLocale(userLang);

/**
 * Json file translation function
 * return key or search value if transaltion doesn't exist
 */
export function __(stringToGet: string): string {
  const v = lang.get(`json.${stringToGet}`);
  return v.length === 0 || v.startsWith('json') ? stringToGet : v;
}

/**
 * php file translation function
 * return key or search value if transaltion doesn't exist
 */
export function ___(scope: string, stringToGet: string): string {
  const v = lang.get(`${scope}.${stringToGet}`);
  return v.length === 0 || v.startsWith('json') ? stringToGet : v;
}
