Repository navigation
Conversation
I18n fallbacks work key by key: when a locale only contains part of a
subtree, I18n.t('app.public') returns that partial subtree and ignores
the fallback locales. Deep-merge the subtrees found along the fallback
chain, so that a locale variant only needs to contain the strings that
differ from its parent locale.
When only one locale of the chain contains the subtree, nothing is
merged and the response is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Address the users with "du" instead of "Sie". The locale files only contain the strings that differ from the formal German (de); every other string falls back to "de". Map the Crowdin language to de-x-informal, add a few informal strings as a starting point, and select the zxcvbn dictionary from the language part of APP_LOCALE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Many German FabLabs and makerspaces address their members informally ("du"), while Fab-manager's German translation addresses them formally ("Sie"). The current
defiles are also a mix of both (eg.app.public.de.ymlhas ~60 formal strings and a few informal ones, sometimes inside the same screen).Crowdin only has one German target language, so there is currently no way to offer both. This PR proposes an informal German locale variant,
de-x-informal, next to the existing formalde, designed so that it only needs to contain the strings that actually differ.CONTRIBUTING.md asks to discuss larger changes first: this PR is meant as a concrete proposal, and I'm happy to change the approach (locale code, file layout, Crowdin setup…) to whatever suits you best.
Design
Locale code:
de-x-informal<html lang>, RSS<language>,Intl.*, etc.de-x-informal → de-x → de(then the default locale chain as before), so any string missing from the informal files falls back to the formal German, key by key, without any extra configuration.APP_LOCALE(with the versions fromyarn.lock):messageformat1.0.2 (angular-translate interpolation) strips subtags until it finds plural rules → usesde;i18next21.6.13 resolves['de-x-informal', 'de', 'en'](it explicitly ignores thexsubtag);intl-messageformat9.11.4 /Intl.PluralRulesresolve it tode.MOMENT_LOCALE,SUMMERNOTE_LOCALE,ANGULAR_LOCALE,FULLCALENDAR_LOCALEandINTL_LOCALEare independent settings: they should simply be set as for the formal German (documented).Front-end translations (
API::TranslationsController)The front-end loads whole subtrees (
I18n.t('app.public')). I18n fallbacks work key by key: when a locale contains only part of a subtree,I18n.treturns that partial subtree and ignores the fallbacks, so the partial informal files would hide all the other strings.The new
TranslationsService.lookupdeep-merges the subtree of every available locale of the fallback chain (least specific first, so the most specific wins;nilvalues don't override). The controller uses it, and keeps the previousI18n.tcall as a fallback, so the behaviour of the existing locales is unchanged (when only one locale of the chain has the subtree, nothing is merged). There is no server-side caching of the translations today; the merge is only done when two locales of the chain actually contain the requested subtree, and AngularJS caches the loaded parts on the client side.Back-end (mails, PDF, Devise messages, …)
Single-key lookups (
I18n.t,tin views/mailers, Devise) already go through the fallbacks chain, so nothing else is needed. Currency formatting (CURRENCY_LOCALE = RAILS_LOCALE) falls back torails.de.ymlas well.Other changes
config/initializers/locale.rb: whitelistde-x-informal.crowdin.yml: map the Crowdin language codede-informaltode-x-informal(languages_mapping/two_letters_code) for every file, so that exports land in eg.config/locales/app.public.de-x-informal.yml. The codede-informalis only my suggestion: please adjust it to the code of the language you create in Crowdin.app.public.de-x-informal.yml,devise.de-x-informal.ymlandmails.de-x-informal.ymlwith a few informal strings, so the mechanism can be tried right away. Crowdin can take over from there.LocaliseLib.zxcvbnDictionnariesnow switches on the language part ofAPP_LOCALE(sode-x-informal, and also eg.es-MX, get their dictionary).doc/environment.md(also added the missingde*values to theRAILS_LOCALElist and fixeden-AU-CA→en-AU, en-CA), and a CHANGELOG entry.How to enable
Request: add the language in Crowdin 🙏
Could you please create the matching language in the Crowdin project "fab-manager"? Suggestion:
Settings → Languages → Custom languages → Add
German, informal(orGerman (du))Germande-informal(or directlyde-x-informal, in which case thelanguages_mappingincrowdin.ymlcan be removed). Please tell me which code you chose and I'll update the mapping.Export of untranslated strings: by default, Crowdin fills untranslated strings with the English source, which would defeat the fallback to the formal German. The informal files should only contain the strings that were actually translated. Options I can see:
de-x-informal:). However, this is a project-wide setting, and the other languages rely on the English placeholders (their fallback chain doesn't includeenin production), so it might need a separate file group or a per-language setting.German, informalfrom the formal German (TM pre-translation), so the exported files are complete and translators only have to fix the strings that use "Sie". Simpler on the Crowdin side, but corrections to the formal strings would no longer be propagated automatically.You know your Crowdin setup much better than I do, so I'd be glad to follow your preference.
I'm happy to help translate/review the informal strings (and to review the formal ones for consistency) once the language exists in Crowdin.
Tests
test/services/translations_service_test.rb: fallback chain, single keys falling back tode, deep merge of subtrees,nilvalues, leaf keys, missing keys, and the real informal files (frontend subtree + Devise message).test/integration/translations_test.rb:GET /api/translations/de-x-informal/app.publicreturns the informal overrides merged with the formal German, plus a leaf lookup and the unchanged behaviour forde.What I ran locally (Ruby 3.2.2 container, PostgreSQL 13, Redis 6; no Elasticsearch):
rails test test/services/translations_service_test.rb test/integration/translations_test.rb: 11 tests, 23 assertions, 0 failures. As a sanity check, the integration test fails with the previous controller code.rails test test/mailers test/integration/rss: 2 tests, 0 failures.rubocopon the changed Ruby files: no offenses.rails runnerwithRAILS_LOCALE=de-x-informal:I18n.default_localeisde, the fallbacks chain isde-x-informal → de-x → de, the mergedapp.publichas exactly the same keys asde, a mail subject uses the informal string while a sibling falls back to the formal one, andnumber_to_currencygives12,50 €.yarn.lock.I did not run the full test suite (it needs Elasticsearch), nor the Jest/ESLint suites (the frontend change is a one-line
switchonFablab.locale.split('-')[0]), nor did I try it in a browser.Known limitation / open question
Jobs that are not enqueued from a request (eg. scheduled reminders from sidekiq-scheduler) run with
I18n.default_locale, which is only the language part ofRAILS_LOCALE(de). Their e-mails therefore use the formal address. This is the same pre-existing behaviour as for the regional variants (eg.de-CHnumber formats, which is why invoices useCURRENCY_LOCALE), so I left it out of this PR; I could address it in a follow-up (eg. by making the jobs default toRAILS_LOCALE) if you think it's worth it.