Skip to content

Commit

Permalink
Set en-US as Default Language Folder for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
jaruba committed Jun 1, 2022
1 parent c5928f7 commit 96c9a04
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/build-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ var files = fs.readdirSync(process.cwd());

fs.mkdirSync(path.join(process.cwd(), 'build'), { recursive: true });

var defaultLang = 'en-US'

files.forEach(function(file) {
if (/[a-z][a-z]-[A-Z][A-Z]\.json$/g.test(file)) {
var lang = file.replace('.json', '');
var translations = JSON.parse(fs.readFileSync(path.join(process.cwd(), file)))
fs.mkdirSync(path.join(process.cwd(), 'build', 'values-' + lang), { recursive: true });
var langFolder = 'values' + (lang !== defaultLang ? '-' + lang : '')
fs.mkdirSync(path.join(process.cwd(), 'build', langFolder), { recursive: true });
let xml = '<?xml version="1.0" encoding="utf-8"?>\n';
xml += '<resources>\n';
Object.keys(translations).forEach(key => {
xml += ' <string name="'+key.toLowerCase()+'">'+translations[key].replace(/{{[^}]+}}/gm, '%s')+'</string>\n';
})
xml += '</resources>';
fs.writeFileSync(path.join(process.cwd(), 'build', 'values-' + lang, 'strings.xml'), xml);
fs.writeFileSync(path.join(process.cwd(), 'build', langFolder, 'strings.xml'), xml);
}
})

0 comments on commit 96c9a04

Please sign in to comment.