Class: Jekyll::Site
- Inherits:
-
Object
- Object
- Jekyll::Site
- Defined in:
- lib/jekyll/locales/site.rb
Overview
Jekyll multilingual support
-
Posts are put under _LANGUAGE/ directories
-
The first language on the config is default
-
Translation strings are store in _data/LANGUAGE.yml
-
The plugin generates a copy of the site for every language at _site/LANGUAGE
Instance Attribute Summary collapse
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
Instance Method Summary collapse
- #default_locale ⇒ Object
- #default_locale? ⇒ Boolean
-
#fallback_locale ⇒ String
There’s always a fallback!.
-
#locales ⇒ Object
Get locales from configuration.
- #locales? ⇒ Boolean
- #original_reset ⇒ Object
-
#process ⇒ Object
Process the site once per available locale.
-
#process_single ⇒ Object
We don’t monkey patch because the Site is already instantiated.
-
#reset ⇒ Object
Makes sure the configuration is set but it doesn’t invalidate the cache.
Instance Attribute Details
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
12 13 14 |
# File 'lib/jekyll/locales/site.rb', line 12 def locale @locale end |
Instance Method Details
#default_locale ⇒ Object
70 71 72 |
# File 'lib/jekyll/locales/site.rb', line 70 def default_locale @default_locale ||= locales.first end |
#default_locale? ⇒ Boolean
74 75 76 |
# File 'lib/jekyll/locales/site.rb', line 74 def default_locale? default_locale == locale end |
#fallback_locale ⇒ String
There’s always a fallback!
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/jekyll/locales/site.rb', line 81 def fallback_locale @fallback_locale ||= {} @fallback_locale[locale] ||= case config['fallback_locale'] when TrueClass, FalseClass, NilClass then default_locale when Hash then config['fallback_locale'][locale] when String then config['fallback_locale'] else Jekyll.logger.warn 'Locales:', "Configuration `fallback_locale` is #{config['fallback_locale'].class}, it should be boolean, Hash or String" nil end || default_locale end |
#locales ⇒ Object
Get locales from configuration
66 67 68 |
# File 'lib/jekyll/locales/site.rb', line 66 def locales @locales ||= config.fetch('locales', []) end |
#locales? ⇒ Boolean
61 62 63 |
# File 'lib/jekyll/locales/site.rb', line 61 def locales? locales.length > 1 end |
#original_reset ⇒ Object
16 |
# File 'lib/jekyll/locales/site.rb', line 16 alias original_reset reset |
#process ⇒ Object
Process the site once per available locale
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jekyll/locales/site.rb', line 30 def process locales.each do |locale| @locale = locale Jekyll.logger.info 'Generating locale:', locale locale_create symlink @filter_cache = {} process_single # The default locale is placed at the root of the # site and everything else is under a subdirectory, but we symlink # root to default_locale for compatibility self_symlink if default_locale? && !redirect? end # XXX: Default is expected by Sutty so we always create it default_delete default_symlink # If we enable the redirector, the root of the site will consist # of an index.html that allows visitors to select their locale. copy_redirector if redirect? # Remove _posts symlink posts_delete end |
#process_single ⇒ Object
We don’t monkey patch because the Site is already instantiated
15 |
# File 'lib/jekyll/locales/site.rb', line 15 alias process_single process |
#reset ⇒ Object
Makes sure the configuration is set but it doesn’t invalidate the cache.
20 21 22 23 24 25 26 27 |
# File 'lib/jekyll/locales/site.rb', line 20 def reset @original_config ||= Marshal.load(Marshal.dump(config)) @config = Marshal.load(Marshal.dump(@original_config)) original_reset locale_config end |