Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
funkwhale.audio
Manage
Activity
Members
Labels
Plan
Issues
8
Issue boards
Milestones
Wiki
Code
Merge requests
8
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
funkwhale
funkwhale.audio
Commits
552ea8be
Verified
Commit
552ea8be
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Better language detection / switching
parent
fd269a26
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-1
1 addition, 1 deletion
.gitignore
scripts/i18n-compile.sh
+5
-1
5 additions, 1 deletion
scripts/i18n-compile.sh
src/App.vue
+47
-1
47 additions, 1 deletion
src/App.vue
src/components/Navigation.vue
+0
-1
0 additions, 1 deletion
src/components/Navigation.vue
with
53 additions
and
4 deletions
.gitignore
+
1
−
1
View file @
552ea8be
...
...
@@ -22,4 +22,4 @@ yarn-error.log*
src/translations.json
src/translations
This diff is collapsed.
Click to expand it.
scripts/i18n-compile.sh
+
5
−
1
View file @
552ea8be
#!/bin/bash -eux
locales
=
$(
tail
-n
+2 src/locales.js |
sed
-e
's/export default //'
| jq
'.locales[].code'
| xargs
echo
)
find locales
-name
'*.po'
| xargs
$(
yarn bin
)
/gettext-compile
--output
src/translations.json
mkdir
-p
src/translations
for
locale
in
$locales
;
do
$(
yarn bin
)
/gettext-compile locales/
$locale
/LC_MESSAGES/app.po
--output
src/translations/
$locale
.json
done
This diff is collapsed.
Click to expand it.
src/App.vue
+
47
−
1
View file @
552ea8be
...
...
@@ -10,7 +10,12 @@
<label
for=
"language"
class=
"label"
>
<translate
translate-context=
"Label for language switcher"
>
Language
</translate>
</label>
<select
id=
"language"
name=
"language"
v-model=
"$language.current"
>
<select
id=
"language"
name=
"language"
:value=
"$language.current"
@
change=
"switchLanguage($event.target.value)"
>
<option
v-for=
"(language, key) in $language.available"
:key=
"key"
...
...
@@ -23,19 +28,60 @@
</
template
>
<
script
>
import
Vue
from
'
vue
'
require
(
"
typeface-noto-sans
"
);
require
(
"
typeface-montserrat
"
);
import
locales
from
'
./locales
'
import
Navigation
from
"
./components/Navigation
"
;
export
default
{
components
:
{
Navigation
},
created
()
{
this
.
autodetectLanguage
()
},
computed
:
{
labels
()
{
return
{};
}
},
methods
:
{
autodetectLanguage
()
{
let
userLanguage
=
navigator
.
language
||
navigator
.
userLanguage
let
available
=
locales
.
locales
.
map
(
e
=>
{
return
e
.
code
})
let
self
=
this
let
candidate
let
matching
=
available
.
filter
((
a
)
=>
{
return
userLanguage
.
replace
(
'
-
'
,
'
_
'
)
===
a
})
let
almostMatching
=
available
.
filter
((
a
)
=>
{
return
userLanguage
.
replace
(
'
-
'
,
'
_
'
).
split
(
'
_
'
)[
0
]
===
a
.
split
(
'
_
'
)[
0
]
})
if
(
matching
.
length
>
0
)
{
candidate
=
matching
[
0
]
}
else
if
(
almostMatching
.
length
>
0
)
{
candidate
=
almostMatching
[
0
]
}
else
{
return
}
this
.
switchLanguage
(
candidate
)
},
switchLanguage
(
newValue
)
{
let
self
=
this
import
(
`./translations/
${
newValue
}
.json`
).
then
((
response
)
=>
{
Vue
.
$translations
[
newValue
]
=
response
.
default
[
newValue
]
}).
finally
(()
=>
{
// set current language twice, otherwise we seem to have a cache somewhere
// and rendering does not happen
self
.
$language
.
current
=
'
noop
'
self
.
$language
.
current
=
newValue
})
}
}
};
</
script
>
<
style
lang=
"scss"
>
...
...
This diff is collapsed.
Click to expand it.
src/components/Navigation.vue
+
0
−
1
View file @
552ea8be
...
...
@@ -62,7 +62,6 @@
<
script
>
export
default
{
data
()
{
console
.
log
(
this
.
$router
)
return
{
showMenu
:
false
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment