Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
72 changes: 72 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,77 @@
# frozen_string_literal: true

# --- Translation Context Plugin (test) ---
require 'tmpdir'

def install_i18n_context_generator!
gem_root = Dir.mktmpdir('i18n-context-generator')
gem_home = File.join(gem_root, 'gems')
install_i18n_context_generator_gem!(gem_root: gem_root, gem_home: gem_home)
load_i18n_context_generator_gem!(gem_home)
end

def install_i18n_context_generator_gem!(gem_root:, gem_home:)
install_env = {
'GEM_HOME' => gem_home,
'GEM_PATH' => gem_home
}

Bundler.with_unbundled_env do
system('git', 'clone', '--depth', '1', 'https://github.com/Automattic/i18n-context-generator.git', gem_root) or
raise 'Failed to clone i18n-context-generator'

Dir.chdir(gem_root) do
system('gem', 'build', 'i18n-context-generator.gemspec', '-o', 'i18n-context-generator.gem') or
raise 'Failed to build i18n-context-generator gem'
system(install_env, 'gem', 'install', '--no-document', '--force',
'--install-dir', gem_home, 'i18n-context-generator.gem') or
raise 'Failed to install i18n-context-generator gem'
end
end
end

def load_i18n_context_generator_gem!(gem_home)
gem_libs = Dir.glob(File.join(gem_home, 'gems', '*', 'lib'))
generator_lib = find_i18n_context_generator_lib(gem_libs)
raise 'Failed to locate i18n-context-generator gem lib directory' unless generator_lib

prepend_load_path(generator_lib)
(gem_libs - [generator_lib]).each do |lib_path|
prepend_load_path(lib_path)
end

require 'i18n_context_generator'
end

def find_i18n_context_generator_lib(gem_libs)
gem_libs.find { |lib_path| File.basename(File.dirname(lib_path)).start_with?('i18n-context-generator-') }
end

def prepend_load_path(lib_path)
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
end

begin
install_i18n_context_generator!
rescue StandardError => e
warn("i18n-context-generator bootstrap failed: #{e.message}")
end

# Import the translation context checker plugin from the dangermattic branch
branch_base = 'https://raw.githubusercontent.com/Automattic/dangermattic/iangmaia/add-translation-context-plugin/lib/dangermattic/plugins'
danger.import_plugin("#{branch_base}/common/inline_markdown_poster.rb")
danger.import_plugin("#{branch_base}/translation_context_checker.rb")

translation_context_checker.check_context_suggestions(
translations: 'WooCommerce/src/main/res/values/strings.xml',
source_paths: ['WooCommerce/src/main/kotlin/'],
provider: :anthropic,
model: 'claude-sonnet-4-6',
report_type: :warning,
inline_mode: :translation_suggestion
)
# --- End Translation Context Plugin ---

github.dismiss_out_of_range_messages

# `files: []` forces rubocop to scan all files, not just the ones modified in the PR
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.woocommerce.android.ui.test

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.woocommerce.android.R

/**
* Test fragment for exercising translation context suggestions.
* This file is intentionally added to test the translation context Danger plugin.
*/
class TranslationContextTestFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val saveButton = view.findViewById<Button>(R.id.save_button)
saveButton.text = getString(R.string.test_order_action_save)

val statusLabel = view.findViewById<TextView>(R.id.status_label)
statusLabel.text = getString(R.string.test_order_status_processing)

val titleLabel = view.findViewById<TextView>(R.id.title_label)
titleLabel.text = getString(R.string.test_store_settings_title)

val noteField = view.findViewById<EditText>(R.id.note_field)
noteField.hint = getString(R.string.test_product_note_placeholder)

val closeButton = view.findViewById<Button>(R.id.close_button)
closeButton.contentDescription = getString(R.string.test_shipping_label_close)

val draftBadge = view.findViewById<TextView>(R.id.draft_badge)
draftBadge.text = getString(R.string.test_order_draft_status)
}
}
9 changes: 9 additions & 0 deletions WooCommerce/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4506,4 +4506,13 @@
<string name="woo_pos_promo_page5_description">Use with WooPayments or Stripe payment gateways.</string>
<string name="woo_pos_promo_next_button">Next</string>
<string name="woo_pos_promo_explore_button">Explore WooCommerce POS</string>

<!-- Translation Context Plugin Test Strings -->
<string name="test_order_action_save">Save</string>
Comment on lines +4510 to +4511
Copy link
Collaborator

@dangermattic dangermattic Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<!-- Translation Context Plugin Test Strings -->
<string name="test_order_action_save">Save</string>
<!-- Label for a save button used in an order-related screen. Tapping this button saves the current action or data in the order flow. -->
<string name="test_order_action_save">Save</string>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that it suggests a max length here (presumably in order for the text to fit the design)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it can return the length if it figures it out somehow based on the context. Though I tweaked the system prompt related to that a little bit, so it adds it only when it has a higher certainty.

<string name="test_order_status_processing">Processing</string>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<string name="test_order_status_processing">Processing</string>
<!-- Displays the 'Processing' status of an order in a status label field. This text indicates that an order is currently being processed. -->
<string name="test_order_status_processing">Processing</string>

Generated by 🚫 Danger

<!-- Screen title -->
<string name="test_store_settings_title">Settings</string>
Comment on lines +4513 to +4514
Copy link
Collaborator

@dangermattic dangermattic Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<!-- Screen title -->
<string name="test_store_settings_title">Settings</string>
<!-- This is the title displayed on a Store Settings screen, shown as a text label in the screen's title area. -->
<string name="test_store_settings_title">Settings</string>

<string name="test_product_note_placeholder">Add a note</string>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<string name="test_product_note_placeholder">Add a note</string>
<!-- Placeholder text displayed inside a note input field, prompting the user to enter a note for a product. The text disappears when the user begins typing. -->
<string name="test_product_note_placeholder">Add a note</string>

Generated by 🚫 Danger

<string name="test_shipping_label_close">Close</string>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<string name="test_shipping_label_close">Close</string>
<!-- Accessibility label (contentDescription) for a close button in a shipping label screen. This text is read by screen readers to describe the button's action to visually impaired users. -->
<string name="test_shipping_label_close">Close</string>

Generated by 🚫 Danger

<string name="test_order_draft_status">Draft</string>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<string name="test_order_draft_status">Draft</string>
<!-- A badge label displayed on an order to indicate its 'Draft' status. This text appears as a status badge on an order screen. -->
<string name="test_order_draft_status">Draft</string>

Generated by 🚫 Danger

</resources>
Loading