Renaming language codes
Sometimes incorrect language code has been made available for translation which should be changed to a new one due to new knowledge. This page contains tips and instructions how to do such moves to ensure smooth transitions. This page assumes we are renaming src
to tgt
.
Prepare the target software
The target software should be able to redirect old language codes to new ones. In case of MediaWiki, there is LanguageCode::DEPRECATED_LANGUAGE_CODE_MAPPING
. languages/messages/MessagesSrc.php
must have $fallback = 'tgt';
and languages/messages/MessagesTgt.php
should have $fallback = 'src';
. Also all languages having src
in their fallback chain should be updated to include tgt
as well. These can be removed once move is over.
Prevent concurrent translation updates
To avoid unexpected processing of translation updates during move, run the following command when using bash
shell to take an exclusive translation synchronization lock. Don't forget the dot at the beginning, otherwise the lock will not be held.
. /home/betawiki/config/bin/synclock
This lock will be held for duration of the session, e.g. until you exit screen
where you used it, or log out from the ssh session if you took the lock outside of it.
Perform rename on repos
For each project, using mediawiki as an example. You can do this in /scratch/exports
where the checkouts already exists. Cloning new ones would take a long time.
cd /scratch/exports
Update checkout:
sudo -u l10n-bot repomulti update mediawiki
Do renames:
php /srv/mediawiki/targets/production/extensions/Translate/scripts/export-rename-language.php --group=core --target=. --source-language src --target-language tgt
# Check matches
Verify:
sudo -u l10n-bot repomulti status mediawiki
Commit:
sudo -u l10n-bot repomulti commit mediawiki
As of 2024-10-21, these commits will fail i18n security checker and require manual submission.
Perform rename on wiki
A useful way to find which namespaces may be appropriate is to run an sql query
SELECT page_namespace, page_title FROM bw_page where page_title LIKE '%/src';
cd /srv/mediawiki/targets/production/extensions/ReplaceText/maintenance
# Get list of namespaces:
php replaceAll.php --listns
# Preview
php replaceAll.php --dry-run --ns 8,9,1206,1207 --regex --rename '/src$' '/tgt'
# Do it, 646 is FuzzyBot
php replaceAll.php --ns 8,9,1206,1207 --regex --rename --user FuzzyBot --yes --summary="Your summary here" '/src$' '/tgt'
This will take a while.
Release translation synchronization lock
The lock will prevent all translation exports and imports, so it is important to release it after you have completed by closing any screens and logging out of the ssh session.
Verify and cleanup
After this and repo updates are finished and merged, you can run autoimport
or autoimport-mediawiki
– there shouldn't be any changes but something might have got out of sync over time that shows up now.
Finally the caches may need to be purged if didn't happen automatically:
# Review
find /resources/caches/translatewiki.net -name "src.cdb"
# Just Do It
b find /resources/caches/translatewiki.net -name "src.cdb" -delete
You want to restrict this to only relevant groups in case the language code is also used in other projects where it was not renamed by changing the path to /resources/caches/translatewiki.net/translate_groupcache-message group id