Compare commits
No commits in common. "develop" and "main" have entirely different histories.
3 changed files with 0 additions and 73 deletions
19
License.txt
19
License.txt
|
@ -1,19 +0,0 @@
|
||||||
Copyright (c) 2023 Ferdinand Kuhl <f.kuhl@digital-competence.de>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
|
@ -1,13 +0,0 @@
|
||||||
{
|
|
||||||
"name": "@digicomp/flow-translation-endpoint",
|
|
||||||
"description": "Connect to Flow's merged and parsed xliff contents",
|
|
||||||
"main": "translate.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"i18n"
|
|
||||||
],
|
|
||||||
"author": "Ferdinand Kuhl",
|
|
||||||
"license": "MIT"
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
// storage for promises with the same ids so the same request is not issued twice
|
|
||||||
const translations = {};
|
|
||||||
|
|
||||||
export function translateIdPatterns(idPatterns)
|
|
||||||
{
|
|
||||||
if (!translations[idPatterns.join(',')]) {
|
|
||||||
translations[idPatterns.join(',')] = getJSON(idPatterns);
|
|
||||||
}
|
|
||||||
return translations[idPatterns.join(',')];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function arrayFromPaths(units)
|
|
||||||
{
|
|
||||||
const result = {};
|
|
||||||
for (const [key, value] of Object.entries(units)) {
|
|
||||||
let cur = result;
|
|
||||||
const parts = key.split('.'),
|
|
||||||
lastPart = parts.pop();
|
|
||||||
|
|
||||||
parts.forEach(function(elem){
|
|
||||||
cur[elem] = cur[elem] || {};
|
|
||||||
cur = cur[elem];
|
|
||||||
});
|
|
||||||
cur[lastPart] = value;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getJSON(idPatterns)
|
|
||||||
{
|
|
||||||
const uri = new URL(document.documentElement.dataset.xliffUri, document.location);
|
|
||||||
uri.searchParams.set(document.documentElement.dataset.xliffParameter, idPatterns);
|
|
||||||
const response = await fetch(uri, {headers: {
|
|
||||||
'Accept': 'application/json',
|
|
||||||
'Accept-Language': document.documentElement.lang,
|
|
||||||
}});
|
|
||||||
if (!response.ok) {
|
|
||||||
return Promise.reject('Unexpected server response');
|
|
||||||
}
|
|
||||||
return await response.json();
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue