OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix locale keys after downloading from crowdin
Oliver Günther2094074e7363
diff --git a/.github/workflows/crowdin.yml b/.github/workflows/crowdin.ymlindex c8a1c832158..2f9e580bfcd 100644--- a/.github/workflows/crowdin.yml+++ b/.github/workflows/crowdin.yml@@ -42,6 +42,7 @@ jobs:with:ref: ${{ matrix.branch }}fetch-depth: 1+ - uses: ruby/setup-ruby@v1- name: "Set crowdin branch name"id: varsenv:@@ -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"diff --git a/script/crowdin/fix_locale_keys.rb b/script/crowdin/fix_locale_keys.rbnew file mode 100644index 00000000000..1ef7096a333--- /dev/null+++ b/script/crowdin/fix_locale_keys.rb@@ -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