Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocking merging on translations #3241

Merged
merged 68 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
63aa013
Automate localizations
porter-stripe Feb 1, 2024
04c1915
Update script path
porter-stripe Feb 1, 2024
948b492
fix stage
porter-stripe Feb 1, 2024
dfa7028
fix pipeline
porter-stripe Feb 1, 2024
7f64fae
Update bitrise.yml
porter-stripe Feb 1, 2024
3289265
Run for all branches (for now)
porter-stripe Feb 1, 2024
14aef9a
Update bitrise.yml
porter-stripe Feb 1, 2024
6cf5086
Update bitrise.yml
porter-stripe Feb 1, 2024
cb9a58b
Update bitrise.yml
porter-stripe Feb 1, 2024
c351ae7
Update bitrise.yml
porter-stripe Feb 1, 2024
32e88b5
Try to fix bundle scope issue
porter-stripe Feb 1, 2024
51369b0
Update bitrise.yml
porter-stripe Feb 2, 2024
6194c27
Only run on the master branch
porter-stripe Feb 2, 2024
7bf69d9
try to make it better
porter-stripe Feb 2, 2024
8e1ed62
Revert "try to make it better"
porter-stripe Feb 2, 2024
7418ea0
Revert "Only run on the master branch"
porter-stripe Feb 2, 2024
cb6f2b8
Test commit
porter-stripe Feb 2, 2024
cd41aa7
Add script to check if strings are untranslated
porter-stripe Feb 2, 2024
ea2f4f9
Test change
porter-stripe Feb 2, 2024
f2cac25
Update bitrise.yml
porter-stripe Feb 2, 2024
775e9c2
Update bitrise.yml
porter-stripe Feb 2, 2024
0916a89
Update check_for_untranslated_strings.rb
porter-stripe Feb 2, 2024
a595cb4
Update check_for_untranslated_strings.rb
porter-stripe Feb 2, 2024
c0d9f4f
Update repo path
porter-stripe Feb 2, 2024
c7fe734
Update check_for_untranslated_strings.rb
porter-stripe Feb 2, 2024
0888670
Fix directory
porter-stripe Feb 2, 2024
6f60af1
Don't change directory
porter-stripe Feb 2, 2024
3e6f595
print directories
porter-stripe Feb 2, 2024
e200c57
Add origin/master
porter-stripe Feb 2, 2024
87d13a4
format
porter-stripe Feb 2, 2024
6c42f9e
Update check_for_untranslated_strings.rb
porter-stripe Feb 3, 2024
59ce62b
Clean up
porter-stripe Feb 3, 2024
36d7601
Try is skippable
porter-stripe Feb 3, 2024
3242daa
Update check_for_untranslated_strings.rb
porter-stripe Feb 3, 2024
82e8f78
Revert "Try is skippable"
porter-stripe Feb 3, 2024
bb75b47
Update check_for_untranslated_strings.rb
porter-stripe Feb 4, 2024
e5617b8
Update check_for_untranslated_strings.rb
porter-stripe Feb 4, 2024
a3636c4
[skip translations] Skip translations
porter-stripe Feb 4, 2024
1b8e6cf
[skip translations] test
porter-stripe Feb 4, 2024
f91d215
Update check_for_untranslated_strings.rb
porter-stripe Feb 4, 2024
ffadb23
Update check_for_untranslated_strings.rb
porter-stripe Feb 4, 2024
46254d5
Re enable other checks
porter-stripe Feb 5, 2024
a90d646
try using a github check
porter-stripe Feb 8, 2024
5f0dbad
Update check-translations.yml
porter-stripe Feb 8, 2024
0f4eba3
Update check-translations.yml
porter-stripe Feb 8, 2024
29ad96d
Update workflow
porter-stripe Feb 8, 2024
419e71f
Update check_for_untranslated_strings.rb
porter-stripe Feb 8, 2024
05bf57d
Update check-translations.yml
porter-stripe Feb 8, 2024
1fb0254
Update check-translations.yml
porter-stripe Feb 8, 2024
1c0dc7c
Update check-translations.yml
porter-stripe Feb 8, 2024
7f55ec6
Update check-translations.yml
porter-stripe Feb 8, 2024
b7d884e
Update check-translations.yml
porter-stripe Feb 8, 2024
c13d783
Update check-translations.yml
porter-stripe Feb 8, 2024
8678db0
Update check-translations.yml
porter-stripe Feb 8, 2024
a76fa0c
Update check-translations.yml
porter-stripe Feb 8, 2024
f670460
Update check-translations.yml
porter-stripe Feb 8, 2024
359d080
Undo some stuff
porter-stripe Mar 15, 2024
2970b63
Undo some more
porter-stripe Mar 15, 2024
9b70884
Use readonly key
porter-stripe Mar 15, 2024
ea80251
Remove push
porter-stripe Mar 15, 2024
45d0567
Exclude other non payments projects from this check
porter-stripe Mar 15, 2024
85c1c06
Update comment for clarity
porter-stripe Mar 15, 2024
c50dfe0
This should make the check fail
porter-stripe Mar 15, 2024
bf2a4b0
Update issue numbers
porter-stripe Mar 15, 2024
614ba97
Try adding more strings
porter-stripe Mar 15, 2024
73b2cd9
Join by comma
porter-stripe Mar 15, 2024
1b603df
Revert "Try adding more strings"
porter-stripe Mar 15, 2024
be3ca86
Revert "This should make the check fail"
porter-stripe Mar 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/check-translations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Check Missing Translations
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
paths:
- '**/Localizable.strings' # Only run this check if localized string files have changed, exclude non-payments projects.
- '!StripeFinancialConnections/**'
- '!StripeIdentity/**'
- '!StripeConnections/**'

jobs:
check-translations:
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v1
with:
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
- name: Install dependencies
run: gem install net-http net-uri json
- name: Run translation check script
env:
LOKALISE_API_KEY: ${{ secrets.LOKALISE_API_KEY_READONLY }}
run: ruby ci_scripts/check_for_untranslated_strings.rb
- name: Read missing translations
id: missing
run: echo "::set-output name=translations::$(<missing_translations.txt)"
- name: Exit if no missing translations
id: check_translations
run: |
if [ -z "${{ steps.missing.outputs.translations }}" ]; then
echo "No missing translations found, exiting..."
exit 0
else
echo "Missing translations detected, continue workflow..."
fi
- uses: peter-evans/[email protected]
id: find_comment
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: Missing Translations
- uses: peter-evans/create-or-update-comment@v4
with:
body: |
⚠️ Missing Translations

The following translations are missing in Lokalise. While they don't need to be downloaded into the codebase as part of this PR, they do need to exist in Lokalise so that they can be downloaded as part of the release process.

${{ steps.missing.outputs.translations }}

By adding the label `ship without translations` to this PR, I acknowledge that there are missing translations.
edit-mode: replace
comment-id: ${{ steps.find_comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Fail if not accepted
if: "steps.missing.outputs.translations && !contains(github.event.pull_request.labels.*.name, 'ship without translations')"
run: exit 1
71 changes: 71 additions & 0 deletions ci_scripts/check_for_untranslated_strings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require 'net/http'
require 'json'
require 'uri'

$SCRIPT_DIR = __dir__
$ROOT_DIR = File.expand_path('..', $SCRIPT_DIR)

def api_get_request(endpoint, token)
uri = URI(endpoint)
req = Net::HTTP::Get.new(uri)
req['X-Api-Token'] = token

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(req)
end

JSON.parse(res.body)
end

def get_added_strings(current_dir)
new_strings = {}

strings_files = `git diff --name-only origin/master...`.split("\n").select { |f| f.end_with?(".strings") }

strings_files.each do |file|
added_lines = `git diff origin/master... -- #{file}`.split("\n").select do |line|
line.start_with?('+') && !line.start_with?('+++') && line.include?('=') && !line.match(/^\/\//)
end

new_strings[file] = added_lines.map do |line|
line.delete_prefix('+').strip.split('=')[0].gsub(/\"/, '').strip
end
end

new_strings
end

def check_lokalise_translations(api_token, project_id, new_added_strings)
keys = api_get_request("https://api.lokalise.com/api2/projects/#{project_id}/keys?limit=5000&include_translations=1", api_token)
missing_translations = []

new_added_strings.each do |file_path, new_strings|
puts "Checking translation for file #{file_path}"

new_strings.each do |str|
key = keys['keys'].find { |k| k['key_name']['other'] == str }

if key
translated_count = key['translations'].count { |t| !t['translation'].empty? }
if translated_count > 30
puts "Translations for '#{str}' exists."
else
puts "Translations for '#{str}' do not exist."
missing_translations << str
end
else
puts "String '#{str}' does not exist. Make sure you have uploaded your strings to Lokalise."
missing_translations << str
end
end
end

missing_translations
end

new_strings_added = get_added_strings($ROOT_DIR)
missing_translations = check_lokalise_translations(ENV['LOKALISE_API_KEY'], '747824695e51bc2f4aa912.89576472', new_strings_added)
puts(missing_translations)
if missing_translations.any?
File.open("missing_translations.txt", 'w') { |f| f.write missing_translations.join(", ") }
end