Module: LokaliseRails

Defined in:
lib/lokalise_rails.rb,
lib/lokalise_rails/railtie.rb,
lib/lokalise_rails/version.rb,
lib/lokalise_rails/task_definition/base.rb,
lib/lokalise_rails/task_definition/exporter.rb,
lib/lokalise_rails/task_definition/importer.rb,
lib/generators/lokalise_rails/install_generator.rb

Defined Under Namespace

Modules: Generators, TaskDefinition Classes: Railtie

Constant Summary collapse

VERSION =
'1.3.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_tokenObject

Returns the value of attribute api_token.



9
10
11
# File 'lib/lokalise_rails.rb', line 9

def api_token
  @api_token
end

.branchObject

Project branch to use



25
26
27
# File 'lib/lokalise_rails.rb', line 25

def branch
  @branch || 'master'
end

.export_optsObject

Options for export rake task



52
53
54
# File 'lib/lokalise_rails.rb', line 52

def export_opts
  @export_opts || {}
end

.file_ext_regexpObject

Regular expression used to select translation files with proper extensions



35
36
37
# File 'lib/lokalise_rails.rb', line 35

def file_ext_regexp
  @file_ext_regexp || /\.ya?ml\z/i
end

.import_optsObject

Options for import rake task



40
41
42
43
44
45
46
47
48
49
# File 'lib/lokalise_rails.rb', line 40

def import_opts
  @import_opts || {
    format: 'yaml',
    placeholder_format: :icu,
    yaml_include_root: true,
    original_filenames: true,
    directory_prefix: '',
    indentation: '2sp'
  }
end

.import_safe_modeObject

Enables safe mode for import. When enabled, will check whether the target folder is empty or not



57
58
59
# File 'lib/lokalise_rails.rb', line 57

def import_safe_mode
  @import_safe_mode.nil? ? false : @import_safe_mode
end

.lang_iso_infererObject

Infers lang ISO for the given translation file



76
77
78
# File 'lib/lokalise_rails.rb', line 76

def lang_iso_inferer
  @lang_iso_inferer || ->(data) { YAML.safe_load(data)&.keys&.first }
end

.locales_pathObject

Full path to directory with translation files



20
21
22
# File 'lib/lokalise_rails.rb', line 20

def locales_path
  @locales_path || "#{Rails.root}/config/locales"
end

.project_idObject

Returns the value of attribute project_id.



9
10
11
# File 'lib/lokalise_rails.rb', line 9

def project_id
  @project_id
end

.skip_file_exportObject

Additional file skip criteria to apply when performing export



62
63
64
# File 'lib/lokalise_rails.rb', line 62

def skip_file_export
  @skip_file_export || ->(_) { false }
end

.timeoutsObject

Set request timeouts for the Lokalise API client



30
31
32
# File 'lib/lokalise_rails.rb', line 30

def timeouts
  @timeouts || {}
end

.translations_converterObject

Converts translations data to the proper format



71
72
73
# File 'lib/lokalise_rails.rb', line 71

def translations_converter
  @translations_converter || ->(raw_data) { raw_data.to_yaml }
end

.translations_loaderObject



66
67
68
# File 'lib/lokalise_rails.rb', line 66

def translations_loader
  @translations_loader || ->(raw_data) { YAML.safe_load raw_data }
end

Class Method Details

.config {|_self| ... } ⇒ Object

Main interface to provide configuration options for rake tasks

Yields:

  • (_self)

Yield Parameters:

  • _self (LokaliseRails)

    the object that the method was called on



15
16
17
# File 'lib/lokalise_rails.rb', line 15

def config
  yield self
end