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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
i18n: t() picks a form when it meets a plural entry instead of crashing on it
Duarte Santos31f39367c863
diff --git a/frontend/src/lib/i18n-core.js b/frontend/src/lib/i18n-core.jsindex 93d255318..7f96fe098 100644--- a/frontend/src/lib/i18n-core.js+++ b/frontend/src/lib/i18n-core.js@@ -70,6 +70,12 @@ export const getVersion = () => version// Translate a source string; {0},{1}… are replaced with args (also on the English fallback).export function t(s, ...args) {let v = dict[s] || s+ // A plural key (an object of forms, read by tn()) reached through plain t() — a call site+ // that was not moved to tn(). Pick a form rather than crash on replaceAll.+ if (v && typeof v === 'object') {+ const forms = v+ v = (typeof args[0] === 'number' && forms[pluralCategory(args[0])]) || forms.other || forms.many || forms.one || s+ }for (let i = 0; i < args.length; i++) v = v.replaceAll('{' + i + '}', args[i])return v}diff --git a/frontend/src/lib/i18n-plural.test.js b/frontend/src/lib/i18n-plural.test.jsindex 19b645c6c..47487e02f 100644--- a/frontend/src/lib/i18n-plural.test.js+++ b/frontend/src/lib/i18n-plural.test.js@@ -1,5 +1,5 @@import { describe, it, expect, afterEach } from 'vitest'-import { tn, _setLangState } from './i18n-core.js'+import { t, tn, _setLangState } from './i18n-core.js'import ru from '../locales/ru.js'import de from '../locales/de.js'@@ -57,4 +57,10 @@ describe('tn() — plural forms from the pack', () => {for (const form of Object.values(value)) expect(typeof form, key).toBe('string')}})++ it('does not crash when a plural key is read through plain t()', () => {+ _setLangState('ru', ru, null, null)+ expect(t('{0} exercises', 5)).toBe('5 упражнений')+ expect(t('{0} exercises', 2)).toBe('2 упражнения')+ })})