-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(i18n): cleanup terms in poeditor
- Loading branch information
Showing
4 changed files
with
86 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { getTerms, deleteTerms } = require("./poeditor"); | ||
|
||
async function main(project_id, api_token) { | ||
const enTranslationFile = './src/i18n/locales/en.json'; | ||
const enTranslations = require(enTranslationFile); | ||
|
||
const terms = await getTerms(project_id, api_token, 'en'); | ||
const cleanableContexts = [ | ||
'"featureDescriptions"', | ||
'"featureNames"', | ||
'"settingsSchemaDescriptions"', | ||
'"settingsSchemaTitles"', | ||
]; | ||
const cleanableTerms = terms | ||
.filter((term) => cleanableContexts.includes(term.context)); | ||
|
||
const termsToClean = cleanableTerms | ||
.filter((term) => !enTranslations[JSON.parse(term.context)][term.term]); | ||
|
||
console.log(`cleanableTerms ${cleanableTerms.length}, termsToClean ${termsToClean.length}`); | ||
const deletionResults = await deleteTerms(project_id, api_token, termsToClean); | ||
console.log(deletionResults); | ||
|
||
} | ||
|
||
const { POEDITOR_PROJECT_ID, POEDITOR_API_TOKEN } = process.env; | ||
main(POEDITOR_PROJECT_ID, POEDITOR_API_TOKEN); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
async function callApi(url, parameters) { | ||
const body = new FormData(); | ||
for (const key in parameters) { | ||
body.set(key, parameters[key]); | ||
} | ||
const resp = await fetch(url, { | ||
method: 'POST', | ||
body, | ||
}); | ||
return await resp.json(); | ||
} | ||
|
||
async function downloadLanguage(project_id, api_token, language) { | ||
console.log(`Downloading ${language.name} ${language.code}`); | ||
|
||
const exportResult = await callApi('https://api.poeditor.com/v2/projects/export', { | ||
api_token, | ||
id: project_id, | ||
language: language.code, | ||
type: 'i18next', | ||
}); | ||
const languageRes = await fetch(exportResult.result.url); | ||
const languageData = await languageRes.json(); | ||
return languageData; | ||
} | ||
|
||
async function getAvaliableLanguages(project_id, api_token) { | ||
const languages = await callApi('https://api.poeditor.com/v2/languages/list', { | ||
api_token, | ||
id: project_id | ||
}); | ||
return languages.result.languages.map((lang) => ({ code: lang.code, name: lang.name })); | ||
} | ||
|
||
async function getTerms(project_id, api_token, language) { | ||
const terms = await callApi('https://api.poeditor.com/v2/terms/list', { | ||
api_token, | ||
id: project_id, | ||
language | ||
}); | ||
return terms.result.terms.map((term) => ({ term: term.term, context: term.context })); | ||
} | ||
|
||
|
||
async function deleteTerms(project_id, api_token, terms) { | ||
const res = await callApi('https://api.poeditor.com/v2/terms/delete', { | ||
api_token, | ||
id: project_id, | ||
data: JSON.stringify(terms) | ||
}); | ||
return res; | ||
} | ||
|
||
|
||
module.exports = { downloadLanguage, getAvaliableLanguages, getTerms, deleteTerms }; |