diff --git a/scripts/build-android.js b/scripts/build-android.js index d8092de7..f3c98963 100755 --- a/scripts/build-android.js +++ b/scripts/build-android.js @@ -15,7 +15,7 @@ const { } = require('./sanitize'); const rootPath = 'android/src/androidMain/res' -const files = fs.readdirSync(process.cwd()) +const files = fs.readdirSync(process.cwd()).filter(file => /[a-z]{2}-[A-Z]{2}\.json$/g.test(file)); fs.mkdirSync(path.join(process.cwd(), rootPath), { recursive: true }); @@ -36,25 +36,40 @@ const escapeXmlString = str => { return str; } -files - .filter(file => /[a-z]{2}-[A-Z]{2}\.json$/g.test(file)) - .forEach(file => { - const langTag = file.replace(/(\w\w-)(\w\w)\.json/,'$1r$2'); - const translations = JSON.parse(fs.readFileSync(path.join(process.cwd(), file))); - let langFolder = 'values'; - if (langTag !== defaultLang) langFolder += `-${langTag}`; - let xml = '\n'; - xml += '\n'; - const dedup = deduplicate(translations); - Object.keys(dedup).forEach(key => { - xml += ` ${escapeXmlString(dedup[key])}\n`; - }); - xml += ''; - fs.mkdirSync(path.join(process.cwd(), rootPath, langFolder), { recursive: true }); - fs.writeFileSync(path.join(process.cwd(), rootPath, langFolder, 'strings.xml'), xml); - if (duplicatedLanguages[langTag]) { - langFolder = `values-${duplicatedLanguages[langTag]}` +function writeLocales() { + let resource = '\n'; + resource +='\n' + resource += ' \n' + files.forEach(file => resource += ` ${file.split('.').shift()}\n`); + resource += ' \n'; + resource += ''; + fs.mkdirSync(path.join(process.cwd(), rootPath, 'values')); + fs.writeFileSync(path.join(process.cwd(), rootPath, 'values', 'array.xml'), resource); +} + +function writeTranslations() { + files + .forEach(file => { + const langTag = file.replace(/(\w\w-)(\w\w)\.json/, '$1r$2'); + const translations = JSON.parse(fs.readFileSync(path.join(process.cwd(), file))); + let langFolder = 'values'; + if (langTag !== defaultLang) langFolder += `-${langTag}`; + let xml = '\n'; + xml += '\n'; + const dedup = deduplicate(translations); + Object.keys(dedup).forEach(key => { + xml += ` ${escapeXmlString(dedup[key])}\n`; + }); + xml += ''; fs.mkdirSync(path.join(process.cwd(), rootPath, langFolder), { recursive: true }); fs.writeFileSync(path.join(process.cwd(), rootPath, langFolder, 'strings.xml'), xml); - } - }); + if (duplicatedLanguages[langTag]) { + langFolder = `values-${duplicatedLanguages[langTag]}` + fs.mkdirSync(path.join(process.cwd(), rootPath, langFolder), { recursive: true }); + fs.writeFileSync(path.join(process.cwd(), rootPath, langFolder, 'strings.xml'), xml); + } + }) +} + +writeLocales() +writeTranslations()