diff --git a/Dangerfile b/Dangerfile index fa44a1c02e8..ea70fdf3a1d 100644 --- a/Dangerfile +++ b/Dangerfile @@ -2,6 +2,41 @@ github.dismiss_out_of_range_messages +unless respond_to?(:translation_context_checker) + require 'bundler' + require 'tmpdir' + + gem_dir = Dir.mktmpdir('i18n-context-generator-gems') + installed = Bundler.with_unbundled_env do + system( + 'gem', 'install', 'i18n-context-generator', '--version', '0.5.1', + '--no-document', '--install-dir', gem_dir + ) + end + raise 'Could not install i18n-context-generator 0.5.1' unless installed + + Dir.glob(File.join(gem_dir, 'gems', '*', 'lib')).each { |path| $LOAD_PATH.unshift(path) } + require 'i18n_context_generator' + + Dir.mktmpdir('dangermattic-translation-context') do |plugin_dir| + cloned = system( + 'git', 'clone', '--quiet', '--depth', '1', '--branch', 'iangmaia/add-translation-context-plugin', + 'https://github.com/Automattic/dangermattic.git', plugin_dir + ) + raise 'Could not load Dangermattic translation context plugin' unless cloned + + danger.import_plugin(File.join(plugin_dir, 'lib/dangermattic/plugins/translation_context_checker.rb')) + end +end + +translation_context_checker.check_context_suggestions( + discovery_mode: :translations, + source_paths: ['WooCommerce/src/main/kotlin/'], + translation_paths: 'WooCommerce/src/main/res/values/strings.xml', + inline_mode: :translation_suggestion, + report_type: :warning +) + # `files: []` forces rubocop to scan all files, not just the ones modified in the PR rubocop.lint(files: [], force_exclusion: true, inline_comment: true, fail_on_inline_comment: true, include_cop_names: true) diff --git a/Gemfile b/Gemfile index 4391918a75a..294f6e34d78 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' -gem 'danger-dangermattic', '~> 1.4' +gem 'danger-dangermattic', git: 'https://github.com/Automattic/dangermattic.git', branch: 'iangmaia/add-translation-context-plugin' gem 'fastlane', '~> 2.237' gem 'fastlane-plugin-firebase_app_distribution', '~> 1.0' gem 'rubocop', '~> 1.88' diff --git a/Gemfile.lock b/Gemfile.lock index 830841162d8..c9d82900a6e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,15 @@ +GIT + remote: https://github.com/Automattic/dangermattic.git + revision: 21a63ef9531f011aff31a07c46128eff4b080570 + branch: iangmaia/add-translation-context-plugin + specs: + danger-dangermattic (1.4.0) + danger (~> 9.6) + danger-plugin-api (~> 1.0) + danger-rubocop (~> 0.13) + i18n-context-generator (~> 0.5) + rubocop (~> 1.63) + GEM remote: https://rubygems.org/ specs: @@ -75,11 +87,6 @@ GEM octokit (>= 4.0) pstore (~> 0.1) terminal-table (>= 1, < 5) - danger-dangermattic (1.4.0) - danger (~> 9.5, >= 9.5.3) - danger-plugin-api (~> 1.0) - danger-rubocop (~> 0.13) - rubocop (~> 1.63) danger-plugin-api (1.0.0) danger (> 2.0) danger-rubocop (0.13.0) @@ -91,6 +98,7 @@ GEM rake (>= 12.0.0, < 14.0.0) domain_name (0.6.20240107) dotenv (2.8.1) + dotstrings (0.6.0) drb (2.2.3) emoji_regex (3.2.3) excon (1.5.0) @@ -255,6 +263,14 @@ GEM mutex_m i18n (1.14.8) concurrent-ruby (~> 1.0) + i18n-context-generator (0.5.1) + concurrent-ruby (~> 1.2) + csv (~> 3.3) + dotstrings (~> 0.6) + oj (~> 3.16) + rexml (~> 3.2) + thor (~> 1.5) + tty-progressbar (~> 0.18) java-properties (0.3.0) jmespath (1.6.2) json (2.20.0) @@ -286,6 +302,9 @@ GEM octokit (6.1.1) faraday (>= 1, < 3) sawyer (~> 0.9) + oj (3.17.4) + bigdecimal (>= 3.0) + ostruct (>= 0.2) open4 (1.3.4) openssl (4.0.2) options (2.3.2) @@ -347,11 +366,18 @@ GEM simctl (1.6.10) CFPropertyList naturally + strings-ansi (0.2.0) terminal-notifier (2.0.0) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) + thor (1.5.0) trailblazer-option (0.1.2) tty-cursor (0.7.1) + tty-progressbar (0.18.3) + strings-ansi (~> 0.2) + tty-cursor (~> 0.7) + tty-screen (~> 0.8) + unicode-display_width (>= 1.6, < 3.0) tty-screen (0.8.2) tty-spinner (0.9.3) tty-cursor (~> 0.7) @@ -377,7 +403,7 @@ PLATFORMS ruby DEPENDENCIES - danger-dangermattic (~> 1.4) + danger-dangermattic! faraday (~> 1.10) fastlane (~> 2.237) fastlane-plugin-firebase_app_distribution (~> 1.0) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/test/TranslationContextPluginFixture.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/test/TranslationContextPluginFixture.kt new file mode 100644 index 00000000000..7b71ea19f72 --- /dev/null +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/test/TranslationContextPluginFixture.kt @@ -0,0 +1,15 @@ +package com.woocommerce.android.ui.test + +import android.content.Context +import com.woocommerce.android.R + +/** + * Test-only resource usages for exercising translation-context suggestions. + */ +internal object TranslationContextPluginTest { + fun orderEditorLabels(context: Context): List = listOf( + context.getString(R.string.translation_context_test_order_save_button), + context.getString(R.string.translation_context_test_order_processing_status), + context.getString(R.string.translation_context_test_order_note_hint) + ) +} diff --git a/WooCommerce/src/main/res/values/strings.xml b/WooCommerce/src/main/res/values/strings.xml index 88b41df6200..45a8c28d9a0 100644 --- a/WooCommerce/src/main/res/values/strings.xml +++ b/WooCommerce/src/main/res/values/strings.xml @@ -4777,4 +4777,7 @@ Update variation %1$s (#%2$s) for product #%3$s We couldn\'t establish a secure connection. Check that your device date and time are correct, then try again. We couldn\'t verify this site\'s security certificate. Contact your hosting provider or site administrator, then try again. + Save + Processing + Add a note