X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2FTechnique.js;h=b289341d34833bbb4b99262885522786260da515;hb=8e274ddec45800cd727bb7138683b81cf2f7dcb1;hp=c1375bb6c787810119c624aa7de5169aafd3e65d;hpb=d7563cd775e2e07bf9d479fece757433533e0ecf;p=alttp.git diff --git a/resources/js/helpers/Technique.js b/resources/js/helpers/Technique.js index c1375bb..b289341 100644 --- a/resources/js/helpers/Technique.js +++ b/resources/js/helpers/Technique.js @@ -19,6 +19,18 @@ export const hasRelations = (tech, type) => getRelations(tech, type).length > 0; export const getLanguages = tech => ['en', ...tech.translations.map(t => t.locale)]; +export const getMatchedLocale = (tech, lang) => { + const direct = tech.translations.find(t => t.locale === lang); + if (direct) { + return direct.locale; + } + const sameLang = tech.translations.find(t => t.locale.substr(0, 2) === lang.substr(0, 2)); + if (sameLang) { + return sameLang.locale; + } + return 'en'; +}; + export const getTranslation = (tech, prop, lang) => { const direct = tech.translations.find(t => t.locale === lang); if (direct) {