Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build/update-locales.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ fi
mv ./options/locale/locale_en-US.json ./options/

# Remove translation under 25% of en_us
baselines=$(wc -l "./options/locale_en-US.json" | cut -d" " -f1)
baselines=$(cat "./options/locale_en-US.json" | wc -l)
baselines=$((baselines / 4))
for filename in ./options/locale/*.json; do
lines=$(wc -l "$filename" | cut -d" " -f1)
if [ $lines -lt $baselines ]; then
lines=$(cat "$filename" | wc -l)
if [ "$lines" -lt "$baselines" ]; then
echo "Removing $filename: $lines/$baselines"
rm "$filename"
fi
Expand Down
13 changes: 6 additions & 7 deletions modules/translation/i18n/localestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,15 @@ func (l *locale) TrString(trKey string, trArgs ...any) string {
var format string
idx, ok := l.store.trKeyToIdxMap[trKey]
if ok {
if msg, ok := l.idxToMsgMap[idx]; ok {
format = msg // use the found translation
} else if def, ok := l.store.localeMap[l.store.defaultLang]; ok {
// try to use default locale's translation
if msg, ok := def.idxToMsgMap[idx]; ok {
format = msg
format = l.idxToMsgMap[idx]
if format == "" { // missing translation in this locale, fallback to default
Comment on lines +134 to +135
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep the old logic? I believe old logic is stricter and better.

If the old logic didn't catch the empty strings, you won't even realize them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be a tool to detect untranslated strings, but currently there isn’t one. (I will continue #34737 after this merged)

With the new logic, empty translations will simply be ignored. I also couldn’t find any mechanism in the old logic that helped surface these missing translations. Without such tooling, it’s impractical to manually discover empty translations, since you can’t reasonably check every page without knowing where the issue occurs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand, it's up to you, you decide.

if def, ok := l.store.localeMap[l.store.defaultLang]; ok {
// try to use default locale's translation
format = def.idxToMsgMap[idx]
}
}
}
if format == "" {
if format == "" { // still missing, use the key itself
format = html.EscapeString(trKey)
}
msg, err := Format(format, trArgs...)
Expand Down
Loading