Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

i18n: an Arabic exercise name keeps its English part's brackets when it wraps

Boris 'B' Kurktchiev8a7118409dc1
diff --git a/frontend/src/lib/exercise-names.test.js b/frontend/src/lib/exercise-names.test.js
index d07149186..36baa44a1 100644
--- a/frontend/src/lib/exercise-names.test.js
+++ b/frontend/src/lib/exercise-names.test.js
@@ -4,7 +4,7 @@ import { EXDB } from './exercises-data.js'
import V13_IDS from './catalogue-v13-ids.json' with { type: 'json' }
import { checkName, stagedExercises } from '../../../scripts/de-name-rules.mjs'
import {
- EXERCISE_NAME_LANGS, _setLangState, derivePack, exerciseNameFor, exerciseNameSearchText
+ EXERCISE_NAME_LANGS, RTL_LANGS, _setLangState, derivePack, exerciseNameFor, exerciseNameSearchText
} from './i18n-core.js'
// Every translated-name pack, checked the same way. The packs are generated from
@@ -254,7 +254,9 @@ for (const lang of EXERCISE_NAME_LANGS) {
const exercise = EXDB.find(e => pack[e.id] && pack[e.id].toLocaleLowerCase(lang) !== e.n.toLocaleLowerCase('en'))
const name = pack[exercise.id]
_setLangState(lang, {}, null, pack)
- expect(exerciseNameFor(exercise)).toBe(`${name} (${exercise.n})`)
+ // A right-to-left language isolates the English part, brackets included (i18n-core exerciseNameFor).
+ const english = RTL_LANGS.has(lang) ? `\u2068(${exercise.n})\u2069` : `(${exercise.n})`
+ expect(exerciseNameFor(exercise)).toBe(`${name} ${english}`)
expect(exerciseNameSearchText(exercise)).toContain(name)
expect(exerciseNameSearchText(exercise)).toContain(exercise.n)
_setLangState(lang, {}, null, pack, false)
diff --git a/frontend/src/lib/i18n-core.js b/frontend/src/lib/i18n-core.js
index c9bb7fe0c..5d22dbef5 100644
--- a/frontend/src/lib/i18n-core.js
+++ b/frontend/src/lib/i18n-core.js
@@ -214,9 +214,16 @@ export const exerciseNameFor = ex => {
return translated.toLocaleLowerCase(lang) === ex.n.toLocaleLowerCase('en')
|| !enParens
? translated
- : `${translated} (${ex.n})`
+ : `${translated} ${englishInParens(ex.n)}`
}
+// In a right-to-left language the English title in brackets is a left-to-right run inside
+// right-to-left text. Left loose, its closing bracket took the paragraph's direction wherever the
+// name broke across two lines, and the second line began with it turned round: "(Lunge". A
+// first-strong isolate (U+2068 … U+2069) lays the brackets out with the words they hold. The marks
+// are invisible and travel with the name to the watch, the widgets and Apple Health.
+const englishInParens = n => (RTL_LANGS.has(baseLang(lang)) ? `\u2068(${n})\u2069` : `(${n})`)
+
// Exercise-name packs written in the language's own casing. German capitalises its nouns and
// lower-cases the adjectives in front of them ("Assistiertes hängendes Knieheben"), which
// title-casing on top would undo. Every other pack is stored lower-case, the way EXDB stores
diff --git a/frontend/src/lib/i18n-core.test.js b/frontend/src/lib/i18n-core.test.js
index a1d97ca7c..937e19696 100644
--- a/frontend/src/lib/i18n-core.test.js
+++ b/frontend/src/lib/i18n-core.test.js
@@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest'
import {
LANGS, INSTR_LANGS, EXERCISE_NAME_LANGS, DATE_LOCALES, DERIVED_LOCALES,
- baseLang, derivePack, dateLocale, getLang, t, _setLangState, exerciseNameClass, exerciseNameFor, CASED_NAME_LANGS
+ baseLang, derivePack, dateLocale, getLang, t, _setLangState, exerciseNameClass, exerciseNameFor, CASED_NAME_LANGS, RTL_LANGS
} from './i18n-core.js'
import { EXDB } from './exercises-data.js'
import de from '../locales/de.js'
@@ -192,7 +192,9 @@ describe('English-name switches with every exercise-name pack', () => {
_setLangState(lang, {}, null, names)
// German keeps its own casing; a lower-case pack is title-cased like English.
const translatedClass = CASED_NAME_LANGS.includes(lang) ? '' : 'capitalize'
- expect(exerciseNameFor(ex)).toBe(`${names[ex.id]} (${ex.n})`)
+ // A right-to-left language isolates the English part, brackets included (exerciseNameFor).
+ const english = RTL_LANGS.has(lang) ? `\u2068(${ex.n})\u2069` : `(${ex.n})`
+ expect(exerciseNameFor(ex)).toBe(`${names[ex.id]} ${english}`)
expect(exerciseNameClass(ex)).toBe(translatedClass)
_setLangState(lang, {}, null, names, false)
expect(exerciseNameFor(ex)).toBe(names[ex.id])