Class: RosettAi::Compiler::LocaleCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/compiler/locale_compiler.rb

Overview

Compiles ruby-i18n YAML locale files into gettext (.pot/.po) and Qt Linguist (.ts) formats.

Reads all *.yml files from the source directory, flattens nested keys into dotted paths, and generates platform-native locale files for distribution.

Constant Summary collapse

PLURAL_FORMS =
['zero', 'one', 'two', 'few', 'many', 'other'].freeze
PLURAL_HEADERS =
{
  'en' => 'nplurals=2; plural=(n != 1);',
  'fr' => 'nplurals=2; plural=(n > 1);',
  'ar' => 'nplurals=6; plural=(n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_dir:, gettext_dir:, qt_dir:) ⇒ LocaleCompiler

Initialize the locale compiler with source and output directories.

Parameters:

  • source_dir (String, Pathname)

    locale YAML directory

  • gettext_dir (String, Pathname)

    gettext output directory

  • qt_dir (String, Pathname)

    Qt .ts output directory



33
34
35
36
37
# File 'lib/rosett_ai/compiler/locale_compiler.rb', line 33

def initialize(source_dir:, gettext_dir:, qt_dir:)
  @source_dir = Pathname.new(source_dir)
  @gettext_dir = Pathname.new(gettext_dir)
  @qt_dir = Pathname.new(qt_dir)
end

Instance Attribute Details

#gettext_dirObject (readonly)

Returns the value of attribute gettext_dir.



26
27
28
# File 'lib/rosett_ai/compiler/locale_compiler.rb', line 26

def gettext_dir
  @gettext_dir
end

#qt_dirObject (readonly)

Returns the value of attribute qt_dir.



26
27
28
# File 'lib/rosett_ai/compiler/locale_compiler.rb', line 26

def qt_dir
  @qt_dir
end

#source_dirObject (readonly)

Returns the value of attribute source_dir.



26
27
28
# File 'lib/rosett_ai/compiler/locale_compiler.rb', line 26

def source_dir
  @source_dir
end

Instance Method Details

#compileHash{Symbol => Array<String>}

Compiles all locale YAML files to gettext and Qt Linguist formats.

Returns:

  • (Hash{Symbol => Array<String>})

    output paths keyed by :gettext and :qt



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rosett_ai/compiler/locale_compiler.rb', line 42

def compile
  locale_files = discover_locale_files
  results = { gettext: [], qt: [] }

  locale_files.each do |file|
    data = RosettAi::YamlLoader.load_file(file)
    locale = data.keys.first
    entries = flatten_keys(data[locale])

    results[:gettext] << compile_gettext(locale, entries)
    results[:qt] << compile_qt(locale, entries)
  end

  results
end