Class: YorikLangHandlerDefault

Inherits:
Object
  • Object
show all
Defined in:
Plugins/yorik_langhandler.rb

Overview

Rewriting of basic Sketchup API class to make locales for plugins using default language. Parent for YorikLangHandler class.

Direct Known Subclasses

YorikLangHandler

Constant Summary collapse

@@LH_ERRORS_FILE =

Since:

  • 1.0

"LangHandler"
@@LH_FILENAMESPACE =

Since:

  • 1.0

File.basename(__FILE__, ".rb")
@@LH_PATH_ROOT =

Since:

  • 1.0

File.dirname(__FILE__).freeze
@@LH_PATH =

Since:

  • 1.0

File.join(@@LH_PATH_ROOT, @@LH_FILENAMESPACE).freeze
@@LH_RESOURCES_DIR =

Since:

  • 1.0

File.join(@@LH_PATH, "Resources").freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lh_data) ⇒ YorikLangHandlerDefault

initialize method

Since:

  • 1.0


57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'Plugins/yorik_langhandler.rb', line 57

def initialize(lh_data)
  @lh_data           = lh_data
  @default_lang_name = @lh_data[:default_lang_name]
  @default_locale    = @lh_data[:default_locale]
  @lang_ini_name     = @lh_data[:lang_ini_name]
  @locale_file_type  = @lh_data[:locale_file_type]
  @resources_dir     = @lh_data[:RESOURCES_DIR]
  @plugin_id         = @lh_data[:PLUGIN_ID]
  @lh_errors_file    = @@LH_ERRORS_FILE
  @lh_resources_dir  = @@LH_RESOURCES_DIR
  @strings           = Hash.new { |hash, key| key }
  check_default_ini_file
  parse
end

Instance Attribute Details

#lh_dataObject (readonly)

Since:

  • 1.0


45
46
47
# File 'Plugins/yorik_langhandler.rb', line 45

def lh_data
  @lh_data
end

#stringsObject (readonly)

Since:

  • 1.0


45
46
47
# File 'Plugins/yorik_langhandler.rb', line 45

def strings
  @strings
end

Class Method Details

.self_file_nameString

Geting this file name

Since:

  • 1.0


76
77
78
# File 'Plugins/yorik_langhandler.rb', line 76

def self.self_file_name
  File.basename(__FILE__, ".*")
end

Instance Method Details

#[](key) ⇒ String

Since:

  • SketchUp 2014


103
104
105
106
107
108
109
# File 'Plugins/yorik_langhandler.rb', line 103

def [](key)
  value = @strings[key]
  if value.is_a?(String)
    value = value.dup
  end
  return value
end

#check_default_ini_fileObject

Checking path to .ini file with locale code. When file does not exists it will be created with default language locale code.

Since:

  • 1.0


84
85
86
87
88
89
90
# File 'Plugins/yorik_langhandler.rb', line 84

def check_default_ini_file
  @lang_ini_path = File.join(@resources_dir, @lang_ini_name)
  unless File.exist?(@lang_ini_path)
    File.open(@lang_ini_path, 'w') { |file|
       file.write(@default_locale) }
  end
end

#find_strings_fileObject

Finding path for .string with message errors file of default locale

Since:

  • 1.0


95
96
97
# File 'Plugins/yorik_langhandler.rb', line 95

def find_strings_file
  File.join(@lh_resources_dir, @default_locale, @lh_errors_file + @locale_file_type)
end