Skip to content

Commit

Permalink
Add locales-android folder for setting up seperate weblate
Browse files Browse the repository at this point in the history
- This is related to #92
  • Loading branch information
MarmadileManteater committed Feb 13, 2024
1 parent d4797a5 commit daca482
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
9 changes: 7 additions & 2 deletions _scripts/webpack.android.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,14 @@ const processLocalesPlugin = new ProcessLocalesPlugin({
inputDir: path.join(__dirname, '../static/locales'),
outputDir: 'static/locales',
})

const processAndroidLocales = new ProcessLocalesPlugin({
compress: false,
inputDir: path.join(__dirname, '../static/locales-android'),
outputDir: 'static/locales-android',
})
config.plugins.push(
processLocalesPlugin,
processAndroidLocales,
new webpack.DefinePlugin({
'process.env.LOCALE_NAMES': JSON.stringify(processLocalesPlugin.localeNames),
'process.env.GEOLOCATION_NAMES': JSON.stringify(fs.readdirSync(path.join(__dirname, '..', 'static', 'geolocations')).map(filename => filename.replace('.json', '')))
Expand All @@ -197,7 +202,7 @@ config.plugins.push(
to: path.join(__dirname, '../dist/web/static'),
globOptions: {
dot: true,
ignore: ['**/.*', '**/locales/**', '**/pwabuilder-sw.js', '**/dashFiles/**', '**/storyboards/**'],
ignore: ['**/.*', '**/locales/**', '**/locales-android/**', '**/pwabuilder-sw.js', '**/dashFiles/**', '**/storyboards/**'],
},
},
]
Expand Down
17 changes: 15 additions & 2 deletions src/renderer/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,26 @@ export async function loadLocale(locale) {
const url = createWebURL(`/static/locales/${locale}.json`)
let data
if (process.env.IS_ANDROID) {
const androidUrl = createWebURL(`/static/locales-android/${locale}.json`)
// Fetch API cannot load file:///. URL scheme "file" is not supported.
data = JSON.parse(await new Promise((resolve, reject) => {
data = Object.assign(JSON.parse(await new Promise((resolve, reject) => {
const req = new XMLHttpRequest()
req.onload = () => resolve(req.responseText)
req.open('GET', url)
req.send()
}))
})), JSON.parse(await new Promise((resolve, reject) => {
const req = new XMLHttpRequest()
req.onload = () => {
if (req.status === 200) {
resolve(req.responseText)
} else {
// silently fail if it doesn't find android specific strings
resolve('{}')
}
}
req.open('GET', androidUrl)
req.send()
})))
} else {
const response = await fetch(url)
data = await response.json()
Expand Down
3 changes: 3 additions & 0 deletions static/locales-android/activeLocales.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"en-US"
]
6 changes: 6 additions & 0 deletions static/locales-android/en-US.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Keep Alive Notification:
Running In Background Message: FreeTube is running in the background
Player Settings:
Use Old Layout For Info: Use old layout for watch video info
Distraction Free Settings:
Hide Thumbnail In Media Controls: Hide thumbnail in media controls notification

0 comments on commit daca482

Please sign in to comment.