Fix locale keys after downloading from crowdin

pull/10015/head
Oliver Günther 3 years ago
parent 4224864743
commit 2094074e73
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 4
      .github/workflows/crowdin.yml
  2. 37
      script/crowdin/fix_locale_keys.rb

@ -42,6 +42,7 @@ jobs:
with:
ref: ${{ matrix.branch }}
fetch-depth: 1
- uses: ruby/setup-ruby@v1
- name: "Set crowdin branch name"
id: vars
env:
@ -67,6 +68,9 @@ jobs:
env:
OPENPROJECT_CROWDIN_PROJECT: ${{ secrets.OPENPROJECT_CROWDINV2_PROJECT }}
OPENPROJECT_CROWDIN_API_KEY: ${{ secrets.OPENPROJECT_CROWDINV2_API_KEY }}
- name: "Fixing translation names"
run: |
ruby script/crowdin/fix_locale_keys.rb
- name: "Commit translations"
run: |
git config user.name "OpenProject Actions CI"

@ -0,0 +1,37 @@
require 'fileutils'
def js_translation?(translation_file_path)
filename = File.basename translation_file_path.to_s
filename.match? /\Ajs-.+\z/
end
Dir.glob('**/config/locales/crowdin/*.yml').each do |crowdin_file|
# Get the line that contains the first language key
language_key = nil
filename = File.basename(crowdin_file)
File.readlines(crowdin_file).each do |line|
if line.match(/^\s*(\S{2,}):\s*$/)
language_key = $1
break
end
end
# Read the language code from the YML index
if language_key.nil? || language_key.length > 5
raise "Failed to detect language from #{crowdin_file}"
end
# Remove any escaped language names
language_key.delete!('"')
# the files should be named like their translation-key
new_filename = "#{js_translation?(filename) ? 'js-' : ''}#{language_key}.yml"
directory = File.dirname(crowdin_file)
new_filepath = File.join(directory, new_filename)
next if crowdin_file == new_filepath
puts "Renaming #{crowdin_file} to #{new_filepath}"
FileUtils.mv crowdin_file, new_filepath
end
Loading…
Cancel
Save