Class Stella::Text
In: lib/stella/text.rb
lib/stella/text/resource.rb
lib/stella/text.rb
Parent: Object

Stella::Text

This is the API for retrieving interface text in Stella. The intended use is to have a single instance of this class although there‘s nothing stopping you (or anyone else!) from having as many instances as you see fit. Currently only yaml files are supported.

Methods

Classes and Modules

Class Stella::Text::Resource

Constants

DEFAULT_LANGUAGE = 'en'.freeze unless defined? LANGUAGE
MESSAGE_NOT_DEFINED = "The message %s is not defined"
RESOURCES_PATH = File.join(STELLA_HOME, "support", "text").freeze unless defined? RESOURCES_PATH
DEFAULT_LANGUAGE = 'en'.freeze unless defined? LANGUAGE
MESSAGE_NOT_DEFINED = "The message %s is not defined"
RESOURCES_PATH = File.join(STELLA_HOME, "support", "text").freeze unless defined? RESOURCES_PATH

Attributes

lang  [R] 
lang  [R] 
resource  [R] 
resource  [R] 

Public Class methods

[Source]

    # File lib/stella/text.rb, line 19
19:     def initialize(language=nil)
20:       @lang = determine_language(language)
21:       @resource = Resource.new(RESOURCES_PATH, @lang)
22:       @available_languages = []
23:     end

[Source]

    # File lib/stella/text.rb, line 19
19:     def initialize(language=nil)
20:       @lang = determine_language(language)
21:       @resource = Resource.new(RESOURCES_PATH, @lang)
22:       @available_languages = []
23:     end

[Source]

    # File lib/stella/text.rb, line 46
46:     def self.supported_language?(language)
47:       return File.exists?(File.join(RESOURCES_PATH, "#{language}.yaml"))
48:     end

[Source]

    # File lib/stella/text.rb, line 46
46:     def self.supported_language?(language)
47:       return File.exists?(File.join(RESOURCES_PATH, "#{language}.yaml"))
48:     end

Public Instance methods

[Source]

    # File lib/stella/text.rb, line 50
50:     def available_languages
51:       #return @available_languages unless @available_languages.empty?
52:       translations = Dir.glob(File.join(RESOURCES_PATH, "*.yaml"))
53:       translations.each do |path|
54:         trans = YAML.load_file(path)
55:         next if !trans || trans.empty? || !trans[:info] || !trans[:info][:enabled]
56:         @available_languages << trans[:info]
57:       end
58:       @available_languages
59:     end

[Source]

    # File lib/stella/text.rb, line 50
50:     def available_languages
51:       #return @available_languages unless @available_languages.empty?
52:       translations = Dir.glob(File.join(RESOURCES_PATH, "*.yaml"))
53:       translations.each do |path|
54:         trans = YAML.load_file(path)
55:         next if !trans || trans.empty? || !trans[:info] || !trans[:info][:enabled]
56:         @available_languages << trans[:info]
57:       end
58:       @available_languages
59:     end

[Source]

    # File lib/stella/text.rb, line 25
25:     def determine_language(language)
26:       return language if Text.supported_language?(language)
27:       Stella::LOGGER.info("There's no translation for '#{language}' yet. Maybe you can help? stella@solutious.com") if language
28:       language = (ENV['STELLA_LANG'] || ENV['LOCALE'] || '').split('_')[0]
29:       Text.supported_language?(language) ? language : DEFAULT_LANGUAGE
30:     end

[Source]

    # File lib/stella/text.rb, line 25
25:     def determine_language(language)
26:       return language if Text.supported_language?(language)
27:       Stella::LOGGER.info("There's no translation for '#{language}' yet. Maybe you can help? stella@solutious.com") if language
28:       language = (ENV['STELLA_LANG'] || ENV['LOCALE'] || '').split('_')[0]
29:       Text.supported_language?(language) ? language : DEFAULT_LANGUAGE
30:     end

[Source]

    # File lib/stella/text.rb, line 37
37:     def err(txtsym, *vars)
38:       return self.parse(MESSAGE_NOT_DEFINED, txtsym) unless @resource.error.has_key?(txtsym)
39:       parse(@resource.error[txtsym], vars)
40:     end

[Source]

    # File lib/stella/text.rb, line 37
37:     def err(txtsym, *vars)
38:       return self.parse(MESSAGE_NOT_DEFINED, txtsym) unless @resource.error.has_key?(txtsym)
39:       parse(@resource.error[txtsym], vars)
40:     end

[Source]

    # File lib/stella/text.rb, line 32
32:     def msg(txtsym, *vars)
33:       return self.parse(MESSAGE_NOT_DEFINED, txtsym) unless @resource.message.has_key?(txtsym)
34:       parse(@resource.message[txtsym], vars)
35:     end

[Source]

    # File lib/stella/text.rb, line 32
32:     def msg(txtsym, *vars)
33:       return self.parse(MESSAGE_NOT_DEFINED, txtsym) unless @resource.message.has_key?(txtsym)
34:       parse(@resource.message[txtsym], vars)
35:     end

[Source]

    # File lib/stella/text.rb, line 42
42:     def parse(text, vars)
43:       sprintf(text, *vars)
44:     end

[Source]

    # File lib/stella/text.rb, line 42
42:     def parse(text, vars)
43:       sprintf(text, *vars)
44:     end

[Validate]