Update gettext:updated_check regenerate pot file

Making the `gettext:updated_check` by completely regenerating the gitlab.pot.

This avoids an issue where `gettext:find` would not pick up on changes
if the file isn't removed first.
This commit is contained in:
Bob Van Landuyt 2018-07-06 14:40:23 +02:00
parent 0ed8f3490e
commit f3fbf50ad8
2 changed files with 24 additions and 18 deletions

View file

@ -281,7 +281,7 @@ Now that the new content is marked for translation, we need to update the PO
files with the following command: files with the following command:
```sh ```sh
bin/rake gettext:find bin/rake gettext:regenerate
``` ```
This command will update the `locale/gitlab.pot` file with the newly externalized This command will update the `locale/gitlab.pot` file with the newly externalized
@ -292,16 +292,6 @@ file in. Once the changes are on master, they will be picked up by
If there are merge conflicts in the `gitlab.pot` file, you can delete the file If there are merge conflicts in the `gitlab.pot` file, you can delete the file
and regenerate it using the same command. Confirm that you are not deleting any strings accidentally by looking over the diff. and regenerate it using the same command. Confirm that you are not deleting any strings accidentally by looking over the diff.
The command also updates the translation files for each language: `locale/*/gitlab.po`
These changes can be discarded, the language files will be updated by Crowdin
automatically.
Discard all of them at once like this:
```sh
git checkout locale/*/gitlab.po
```
### Validating PO files ### Validating PO files
To make sure we keep our translation files up to date, there's a linter that is To make sure we keep our translation files up to date, there's a linter that is

View file

@ -19,6 +19,23 @@ namespace :gettext do
Rake::Task['gettext:po_to_json'].invoke Rake::Task['gettext:po_to_json'].invoke
end end
task :regenerate do
# Remove all translated files, this speeds up finding
FileUtils.rm Dir['locale/**/gitlab.*']
# remove the `pot` file to ensure it's completely regenerated
FileUtils.rm_f 'locale/gitlab.pot'
Rake::Task['gettext:find'].invoke
# leave only the required changes.
`git checkout -- locale/*/gitlab.po`
puts <<~MSG
All done. Please commit the changes to `locale/gitlab.pot`.
MSG
end
desc 'Lint all po files in `locale/' desc 'Lint all po files in `locale/'
task lint: :environment do task lint: :environment do
require 'simple_po_parser' require 'simple_po_parser'
@ -50,13 +67,12 @@ namespace :gettext do
end end
task :updated_check do task :updated_check do
pot_file = 'locale/gitlab.pot'
# Removing all pre-translated files speeds up `gettext:find` as the # Removing all pre-translated files speeds up `gettext:find` as the
# files don't need to be merged. # files don't need to be merged.
# Having `LC_MESSAGES/gitlab.mo files present also confuses the output. # Having `LC_MESSAGES/gitlab.mo files present also confuses the output.
FileUtils.rm Dir['locale/**/gitlab.*'] FileUtils.rm Dir['locale/**/gitlab.*']
FileUtils.rm_f pot_file
# Make sure we start out with a clean pot.file
`git checkout -- locale/gitlab.pot`
# `gettext:find` writes touches to temp files to `stderr` which would cause # `gettext:find` writes touches to temp files to `stderr` which would cause
# `static-analysis` to report failures. We can ignore these. # `static-analysis` to report failures. We can ignore these.
@ -64,18 +80,18 @@ namespace :gettext do
Rake::Task['gettext:find'].invoke Rake::Task['gettext:find'].invoke
end end
pot_diff = `git diff -- locale/gitlab.pot`.strip pot_diff = `git diff -- #{pot_file} | grep -E '^(\\+|-)msgid'`.strip
# reset the locale folder for potential next tasks # reset the locale folder for potential next tasks
`git checkout -- locale` `git checkout -- locale`
if pot_diff.present? if pot_diff.present?
raise <<~MSG raise <<~MSG
Newly translated strings found, please add them to `gitlab.pot` by running: Newly translated strings found, please add them to `#{pot_file}` by running:
rm locale/**/gitlab.*; bin/rake gettext:find; git checkout -- locale/*/gitlab.po bin/rake gettext:regenerate
Then commit and push the resulting changes to `locale/gitlab.pot`. Then commit and push the resulting changes to `#{pot_file}`.
The diff was: The diff was: