Class: Jekyll::Site

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#localeObject (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_localeObject



62
63
64
# File 'lib/jekyll/locales/site.rb', line 62

def default_locale
  @default_locale ||= locales.first
end

#default_locale?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/jekyll/locales/site.rb', line 66

def default_locale?
  default_locale == locale
end

#localesObject

Get locales from configuration



58
59
60
# File 'lib/jekyll/locales/site.rb', line 58

def locales
  @locales ||= config.fetch('locales', [])
end

#locales?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/jekyll/locales/site.rb', line 53

def locales?
  locales.length > 1
end

#processObject

Process the site once per available locale



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jekyll/locales/site.rb', line 18

def process
  locales.each do |locale|
    @locale = locale

    Jekyll.logger.info 'Generating locale:', locale

    locale_create
    locale_config

    Jekyll.logger.info 'Destination:', config['destination']
    Jekyll.logger.info 'Base URL:', config['baseurl']

    symlink
    @filter_cache = {}
    reset
    setup
    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_singleObject

We don’t monkey patch because the Site is already instantiated



15
# File 'lib/jekyll/locales/site.rb', line 15

alias process_single process