Class: Jekyll::GeneratorSingleSource::I18nFile
- Inherits:
-
Object
- Object
- Jekyll::GeneratorSingleSource::I18nFile
- Defined in:
- lib/jekyll/generator-single-source/i18n_file.rb
Defined Under Namespace
Classes: MissingI18nFile
Instance Attribute Summary collapse
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#src_path ⇒ Object
readonly
Returns the value of attribute src_path.
Class Method Summary collapse
Instance Method Summary collapse
- #exists? ⇒ Boolean
- #exists_in_locale? ⇒ Boolean
- #full_file_path_in_default_locale ⇒ Object
- #full_file_path_in_locale ⇒ Object
-
#initialize(file:, locale:, src_path:, site:) ⇒ I18nFile
constructor
A new instance of I18nFile.
- #missing_translation? ⇒ Boolean
-
#relative_file_path ⇒ Object
path to the file relative to src_path including.
Constructor Details
#initialize(file:, locale:, src_path:, site:) ⇒ I18nFile
Returns a new instance of I18nFile.
12 13 14 15 16 17 |
# File 'lib/jekyll/generator-single-source/i18n_file.rb', line 12 def initialize(file:, locale:, src_path:, site:) @file = file # unlocalized file format @locale = locale # locale in which we want the file @src_path = src_path # src_path relative to app @site = site end |
Instance Attribute Details
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
6 7 8 |
# File 'lib/jekyll/generator-single-source/i18n_file.rb', line 6 def locale @locale end |
#src_path ⇒ Object (readonly)
Returns the value of attribute src_path.
6 7 8 |
# File 'lib/jekyll/generator-single-source/i18n_file.rb', line 6 def src_path @src_path end |
Class Method Details
.exists?(file:, locale:, src_path:, site:) ⇒ Boolean
8 9 10 |
# File 'lib/jekyll/generator-single-source/i18n_file.rb', line 8 def self.exists?(file:, locale:, src_path:, site:) new(file:, locale:, src_path:, site:).exists? end |
Instance Method Details
#exists? ⇒ Boolean
35 36 37 |
# File 'lib/jekyll/generator-single-source/i18n_file.rb', line 35 def exists? File.exist?(full_file_path_in_locale) end |
#exists_in_locale? ⇒ Boolean
39 40 41 42 43 44 45 |
# File 'lib/jekyll/generator-single-source/i18n_file.rb', line 39 def exists_in_locale? if @locale == I18n.default_locale.to_s File.exist?(full_file_path_in_default_locale) else File.exist?(full_file_path_in_locale_folder) end end |
#full_file_path_in_default_locale ⇒ Object
19 20 21 |
# File 'lib/jekyll/generator-single-source/i18n_file.rb', line 19 def full_file_path_in_default_locale @full_file_path_in_default_locale ||= File.join(@site.source, @src_path, @file) end |
#full_file_path_in_locale ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/jekyll/generator-single-source/i18n_file.rb', line 23 def full_file_path_in_locale @full_file_path_in_locale ||= if @locale == I18n.default_locale.to_s full_file_path_in_default_locale else full_file_path_in_locale_with_fallback end end |
#missing_translation? ⇒ Boolean
31 32 33 |
# File 'lib/jekyll/generator-single-source/i18n_file.rb', line 31 def missing_translation? !exists_in_locale? end |
#relative_file_path ⇒ Object
path to the file relative to src_path including
48 49 50 51 52 53 54 |
# File 'lib/jekyll/generator-single-source/i18n_file.rb', line 48 def relative_file_path @relative_file_path ||= if @src_path.to_s.empty? @file else File.join(@src_path, @file) end end |