Renaming language codes

Jump to navigation Jump to search

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::$deprecatedLanguageCodeMapping. 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.

Halt translation updates

To avoid unexpected processing during move, it's a good idea to stop translation updates.

  • Edit /etc/cron.d/wikimaintenance to comment out appropriate autoimport call.
  • Exports are systemd timer units. TODO: how to disable?

Perform rename on repos

For each project, using mediawiki as an example.

Update checkout:

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


repomulti status mediawiki


repomulti commit mediawiki

Perform rename on wiki

cd /srv/mediawiki/targets/productions/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 646 --yes --summary="Your summary here" '/src$' '/tgt'

This will take a while.

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/ -name "src.cdb"
# Just Do It
find /resources/caches/ -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/ group id

Restore translation updates

Edit /etc/cron.d/wikimaintenance and uncomment appropriate autoimport line.

See also