Class: Fastlane::Helper::GlossaryLoader
- Inherits:
-
Object
- Object
- Fastlane::Helper::GlossaryLoader
- Defined in:
- lib/fastlane/plugin/translate_gpt_release_notes/helper/glossary_loader.rb
Overview
Loads glossary terms from curated JSON files or localization directories. Supports ARB, Apple .strings, Android strings.xml, JSON i18n, and XLIFF formats. Filters terms by fuzzy matching against source text to keep prompts concise.
Constant Summary collapse
- FORMAT_EXTENSIONS =
Supported localization file extensions and their format identifiers
{ '.arb' => :arb, '.strings' => :strings, '.xml' => :android_xml, '.json' => :json, '.xliff' => :xliff, '.xlf' => :xliff }.freeze
- MIN_WORD_LENGTH =
Minimum word length for individual word matching in fuzzy search
4- MAX_TERM_LENGTH =
Maximum term length in characters. Longer terms are full sentences/paragraphs and not useful as glossary entries for translation prompts.
80- STOPWORDS =
Common English stopwords excluded from individual word matching. These are too generic to be useful for glossary term matching and cause excessive false positives with real-world localization files.
Set.new(%w[ about also back been come could does done each even from give goes gone good have here high into just keep know like long look made make many more most much must need only once open over part read real right same show side some such sure take than that them then they this time used very want well what when will with work your ]).freeze
Instance Method Summary collapse
-
#initialize(params) ⇒ GlossaryLoader
constructor
A new instance of GlossaryLoader.
-
#terms_for(source_text, target_locale) ⇒ Hash
Returns glossary terms relevant to the source text for a specific target locale.
Constructor Details
#initialize(params) ⇒ GlossaryLoader
Returns a new instance of GlossaryLoader.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/glossary_loader.rb', line 42 def initialize(params) @glossary = {} @source_locale = params[:master_locale] || 'en-US' load_from_file(params[:glossary]) if params[:glossary] load_from_directory(params[:glossary_dir]) if params[:glossary_dir] if @glossary.empty? UI.("Glossary: No terms loaded") else UI.("Glossary: Loaded #{@glossary.size} source terms") end end |
Instance Method Details
#terms_for(source_text, target_locale) ⇒ Hash
Returns glossary terms relevant to the source text for a specific target locale. Applies fuzzy matching to include only terms that appear in the source text.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/glossary_loader.rb', line 62 def terms_for(source_text, target_locale) canonical = canonicalize_locale(target_locale) language_only = canonical.split('-').first result = {} @glossary.each do |source_term, locale_translations| next unless fuzzy_match?(source_term, source_text) # Try canonical locale first, then language-only, then any matching language translation = locale_translations[canonical] || locale_translations[language_only] || find_language_match(locale_translations, language_only) result[source_term] = translation if translation end result end |