12 |
13 |
--------------------------------------------------------------------------------
/docs/_config.yml:
--------------------------------------------------------------------------------
1 | name: Jekyll Locale
2 | description: A Localization plugin for Jekyll
3 | baseurl: ""
4 | collections:
5 | docs:
6 | output: true
7 | livereload: true
8 |
9 | localization:
10 | mode: manual
11 | content_dir: _localizations
12 | locales_set:
13 | fr:
14 | label: Français
15 | en-US:
16 | label: English US
17 |
18 | defaults:
19 | - scope:
20 | path: ""
21 | values:
22 | layout: default
23 | plugins:
24 | - jekyll-locale
25 | - jekyll-mentions
26 | exclude:
27 | - vendor/
28 | - .gitignore
29 | - .jekyll-cache
30 | - CNAME
31 | - icomoon-selection.json
32 | - readme.md
33 |
--------------------------------------------------------------------------------
/docs/_data/filter_examples.yml:
--------------------------------------------------------------------------------
1 | prefix_locale:
2 | en:
3 | - input: "{{ 'about' | prefix_locale }}"
4 | output: "/about"
5 | - input: "{{ '//about//' | prefix_locale }}"
6 | output: "/about/"
7 | - input: "{{ 'about me' | prefix_locale }}"
8 | output: "/about me"
9 | - input: "{{ 'https://www.example.com/about/' | prefix_locale }}"
10 | output: "https://www.example.com/about/"
11 |
12 | fr:
13 | - input: "{{ 'about' | prefix_locale }}"
14 | output: "/fr/about"
15 | - input: "{{ '//about//' | prefix_locale }}"
16 | output: "/fr/about/"
17 | - input: "{{ 'about me' | prefix_locale }}"
18 | output: "/fr/about me"
19 | - input: "{{ 'https://www.example.com/about/' | prefix_locale }}"
20 | output: "https://www.example.com/about/"
21 |
--------------------------------------------------------------------------------
/docs/_data/locales/en-US.yml:
--------------------------------------------------------------------------------
1 | sidebar:
2 | - title: Orientation
3 | docs:
4 | - title: Configuration
5 | link: /configuration/
6 | - title: Auto Mode
7 | link: /modes/auto/
8 | - title: Manual Mode
9 | link: /modes/manual/
10 | - title: Usage
11 | docs:
12 | - title: Introduction
13 | link: /usage/intro/
14 | - title: Advanced Usage
15 | link: /usage/advanced/
16 | - title: Liquid Filters
17 | docs:
18 | - title: localize_date
19 | link: /filters/localize_date/
20 | - title: prefix_locale
21 | link: /filters/prefix_locale/
22 |
23 | available_locales: This Page is also available in the following locales
24 | copyright_preface: The contents of this website are
25 | license_preface: under the terms of the
26 | about_page:
27 | title: About
28 | link: /about/
29 | translated_by: "This page has been translated by:"
30 |
--------------------------------------------------------------------------------
/docs/_data/locales/fr.yml:
--------------------------------------------------------------------------------
1 | sidebar:
2 | - title: Commencer
3 | docs:
4 | - title: Configuration
5 | link: /configuration/
6 | - title: Mode automatique
7 | link: /modes/auto/
8 | - title: Mode manuel
9 | link: /modes/manuel/
10 | - title: Utilisation
11 | docs:
12 | - title: Introduction
13 | link: /utilisation/intro/
14 | - title: Utilisation avancée
15 | link: /utilisation/avancee/
16 | - title: Filtres Liquid
17 | docs:
18 | - title: localize_date
19 | link: /filtres/localize_date/
20 | - title: prefix_locale
21 | link: /filtres/prefix_locale/
22 |
23 | available_locales: Cette page est aussi disponible dans les langues suivantes
24 | copyright_preface: Tous les contenus de ce site
25 | license_preface: selon les termes de la
26 | about_page:
27 | title: À propos
28 | link: /a-propos/
29 | translated_by: "Cette page a été traduite par :"
30 |
--------------------------------------------------------------------------------
/docs/_docs/configuration.md:
--------------------------------------------------------------------------------
1 | ---
2 | permalink: /configuration/
3 | ---
4 |
5 | The plugin has been *preconfigured* with the following:
6 |
7 | ```yaml
8 | localization:
9 | mode : manual # Sets the 'handler mode'
10 | locale : en-US # Sets the 'default locale' for the site
11 | data_dir : locales # Sets the base location for translation data, within your site's `data_dir`.
12 | content_dir: _locales # Sets the base location for placing files to be re-rendered. Ignored in auto mode.
13 | locales_set: [] # A list of locales the site will re-render files into
14 | exclude_set: [] # A list of file paths the site will not re-render in "auto" mode.
15 | ```
16 |
17 | * ### `data_dir`
18 |
19 | This setting defines the base location for *the translation data*, within your site's configured `data_dir`.
20 |
21 | The value defaults to `"locales"`. This implies that the plugin looks for "translation data" in either `_data/locales/` or a
22 | data file named `locales`. e.g. `_data/locales.yml` or `_data/locales.json`, etc.
23 |
24 | Irrespective of the format, the data should be a Hash table / dictionary of key-value pairs where the main key should
25 | correspond to locale defined in the `locales_set` array or the default locale `en-US`, and the subkeys set to string
26 | values.
27 |
28 | #### Example of a single data file corresponding to multiple locales
29 |
30 | ```yaml
31 | # ------------------------
32 | # _data/locales.yml
33 | # ------------------------
34 |
35 | # English US
36 | en-US:
37 | greeting: Hello
38 | user: user
39 | navigation:
40 | home: Home
41 | about: About
42 | contact: Contact
43 |
44 | # French
45 | fr-FR:
46 | greeting: Bonjour
47 | user: l' usager
48 | navigation:
49 | home: Accueil
50 | about: À propos
51 | contact: Contacter
52 | ```
53 |
54 | #### Example of dedicated data files corresponding to a single locale
55 |
56 | ```yaml
57 | # -------------------------
58 | # _data/locales/en-US.yml
59 | # -------------------------
60 | #
61 | # English US
62 | greeting: Hello
63 | user: user
64 | navigation:
65 | home: Home
66 | about: About
67 | contact: Contact
68 | ```
69 |
70 | ```yaml
71 | # -------------------------
72 | # _data/locales/fr-FR.yml
73 | # -------------------------
74 | #
75 | # French
76 | greeting: Bonjour
77 | user: l' usager
78 | navigation:
79 | home: Accueil
80 | about: À propos
81 | contact: Contacter
82 | ```
83 |
84 | * ### `content_dir`
85 |
86 | Ignored in "auto mode", this setting defines the base location for placing "the physical copies" of the canonical pages and
87 | documents. Refer `mode` sub-section below for further details.
88 |
89 | The default setting is `_locales`
90 |
91 | * ### `locales_set`
92 |
93 | Empty by default, this setting defines what locales to be used when "localizing" a site. Listing a locale (other than the
94 | default locale) will cause the entire site to render for that locale and the default locale while in "auto mode".
95 |
96 | You may also define this setting as an object with key-value pairs where keys are locale identifiers and values their metadata:
97 |
98 | ```yaml
99 | localization:
100 | locales_set:
101 | en:
102 | label: English
103 | img: img/english.png
104 | fr:
105 | label: Français
106 | img: img/french.png
107 | ```
108 | *Metadata keys can be any string other than `id`.*
109 |
110 | * ### `locale`
111 |
112 | Set to `en-US` by default, this setting defines the default locale of the site and will not be prepended to the URL of the
113 | generated files.
114 |
115 | * ### `exclude_set`
116 |
117 | Empty by default, this setting defines what files to be *excluded* from being duplicated and re-rendered in the "auto" mode.
118 | Ignored in "manual" mode.
119 |
120 | * ### `mode`
121 |
122 | This setting defines the plugin's operation strategy.
123 |
124 | When set to **`auto`**, the plugin will initialize a generator that will simply duplicate *every page and document set to be
125 | written to destination*, and re-render them into destination, for every locale defined in the `localization.locales_set`
126 | setting.
127 |
128 | This mode will increase your build times in proportion to the total number pages, writable-documents and locales listed but
129 | will result in simply the same canonical output and the canonical url prepended with an iterated locale.
130 |
131 | For example, if one were to configure the plugin with `locales_set: ["de", "fr", "en-US", "es"]`, then a file named `about.md`
132 | will result in the following files:
133 | * `_site/about.html`
134 | * `_site/de/about.html`
135 | * `_site/es/about.html`
136 | * `_site/fr/about.html`
137 |
138 | Setting `mode` to any other value will automatically default to `"manual"` which **requires** you to create physical files in a
139 | special directory (as configured under `localization["content_dir"]`) to render localized copies.
140 |
141 | Refer the page on [manual mode](../modes/manual/) for more details.
142 |
--------------------------------------------------------------------------------
/docs/_docs/filters/localize-date.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Localize Date Filter
3 | permalink: /filters/localize_date/
4 | ---
5 |
17 |
18 | This plugin provides a `localize_date` filter to aid in localizing valid date strings. It takes an optional parameter to specify
19 | the format of the output string.
20 |
21 | The filter technically delegates to the `I18n` module and therefore requires the translation data to follow a certain convention
22 | to pass through without errors.
23 |
24 | ```yaml
25 | date:
26 | day_names : # Array of Day names in full. e.g. "Sunday", "Monday", ...
27 | month_names : # Array of Month names in full. e.g. "January", "February", ...
28 | abbr_day_names : # Array of abbreviations of above Day names. e.g. "Sun", "Mon", ...
29 | abbr_month_names : # Array of abbreviations of above Month names. e.g. "Jan", "Feb", ...
30 | time:
31 | am: "am" # Placeholder for Ante-Meridian
32 | pm: "pm" # Placeholder for Post-Meridian
33 | formats: # A set of predefined strftime formats
34 | default: "%B %d, %Y %l:%M:%S %p %z" # Used by default if no other `format` has been specified.
35 | # my_format: # A valid strftime format of your choice.
36 | # Usage: {% raw %}{{ your_date | localize_date: ":my_format" }}{% endraw %}
37 | ```
38 |
39 | #### Requirements
40 |
41 | The plugin also places a few conventions to streamline usage:
42 | * All datetime data should be encompassed under a `locale_date` key for each locale except the default locale, for which, the
43 | datetime data has been set by default. But you're free to *redefine* it when necessary.
44 | * The array of names are filled in by default using values defined in Ruby's `Date` class.
45 | * The array of full day names and full month names have `nil` as the first entry. So locales for non-English languages should
46 | have `nil` as the first entry. (In YAML, null list item can be written as simply `~`)
47 | * The optional parameter for the filter, `format` should either be a string that corresponds to the symbol of the `formats`
48 | subkey (e.g. `":default"`) or a valid `strftime` format.
49 |
--------------------------------------------------------------------------------
/docs/_docs/filters/prefix-locale.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Prefix Locale Filter
3 | permalink: /filters/prefix_locale/
4 | ---
5 |
6 | This is a basic helper to convert a simple string devoid of whitespaces, into a URI relative to the server root and current
7 | locale. The generated URI will essentially have `/[locale]` (or just `/` for the default locale) prepended to the given `input`.
8 |
9 | The only validations this filter involve are checking if the given `input` is a String or if the input is an absolute URI.
10 | Additionally, the filter strips away multiple slashes in the input string.
11 |
12 |
13 |
14 |
15 |
Default Locale: en
16 |
Current Locale: en
17 |
18 |
19 |
20 |
Input
21 |
Output
22 |
23 |
24 |
25 | {% for example in site.data.filter_examples.prefix_locale.en %}
26 |
27 |
28 | {{ example.input }}
29 |
30 |
31 | {{ example.output }}
32 |
33 |
34 | {% endfor %}
35 |
36 |
37 |
38 |
39 |
40 |
Default Locale: en
41 |
Current Locale: fr
42 |
43 |
44 |
45 |
Input
46 |
Output
47 |
48 |
49 |
50 | {% for example in site.data.filter_examples.prefix_locale.fr %}
51 |
52 |
53 | {{ example.input }}
54 |
55 |
56 | {{ example.output }}
57 |
58 |
59 | {% endfor %}
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/docs/_docs/modes/auto-mode.md:
--------------------------------------------------------------------------------
1 | ---
2 | permalink: /modes/auto/
3 | ---
4 |
5 | This mode generates a localized version of *every published page / document* in your site, for each locale supported, by default.
6 | In other words, if your site contains 1 post and 2 standalone pages published and the site is configured to render in 3 locales,
7 | then this "mode" will generate a total of 1 x 2 x 3 web pages.
8 |
9 | To prevent a certain file from being localized automatically, you may blacklist the file by listing it under the
10 | `localization.exclude_set` key in your config file.
11 |
12 | ```yaml
13 | localization:
14 | mode: auto
15 | locale: en
16 | locales_set: ["en", "fr"]
17 | exclude_set:
18 | - _posts/2018-10-18-english-only.md
19 | - _puppies
20 | ```
21 |
22 | ### Gotchas
23 |
24 | This mode was originally intended for those sites that offer the same content with multiple localized interfaces. That is, sites
25 | in which only the "*presentational*" aspects are localized and the content remains the same.
26 |
27 | As a result, this mode has the following shortcomings:
28 | * The localized page has the same attributes as the canonical page / document — they have the same `path`,
29 | `relative_path`, `data`, `content`, etc. The only attribute they differ in is their `url` and their Liquid representation.
30 | * These attributes cannot be modified.
31 | * The localized object is a descendant of `Jekyll::Page` even if the canonical object is a Post or any other collection
32 | document. This means that the localized object may not respond to certain attributes of the canonical object.
33 | (e.g. a document's `date`)
34 |
--------------------------------------------------------------------------------
/docs/_docs/modes/manual-mode.md:
--------------------------------------------------------------------------------
1 | ---
2 | permalink: /modes/manual/
3 | ---
4 |
5 | The key features of this mode are:
6 | * The physical files are handled like any other file in the site, but, they **should partially mirror** their
7 | counterpart — **their relative_paths should match**.
8 | * If an original file contains front matter, the physical copy should contain front matter as well.
9 | * Physical copies can render different content and into a different layout, if desired.
10 | * Physical copies of posts and other writable *documents* can be rendered to a different `slug` by defining the `slug` key in
11 | the front matter.
12 |
13 | This mode requires the user to provide physical files in the configured `content_dir` with sub-directories that match
14 | the defined locales.
15 |
16 | For example, the following directory structure
17 |
18 | ```
19 | .
20 | ├── _config.yml
21 | ├── _locales
22 | | ├── es
23 | | | ├── tips/
24 | | | | └── optimized-site.md
25 | | | ├── _posts/
26 | | | ├──└── 2018-09-30-hello-world.md
27 | | ├── fr
28 | | | ├── _posts/
29 | | └──└──└── 2018-09-30-hello-world.md
30 | ├── _posts
31 | | └── 2018-09-30-hello-world.md
32 | ├── english
33 | | └── its-a-new-day.md
34 | ├── tips
35 | | ├── optimized-site.md
36 | └──└── url-filters-in-templates.md
37 | ```
38 | will result in the generation of just the following files:
39 |
40 | ```
41 | _site/2018-09-30-hello-world.html
42 | _site/english/its-a-new-day.html
43 | _site/es/2018-09-30-hello-world.html
44 | _site/es/tips/optimized-site.html
45 | _site/fr/2018-09-30-hello-world.html
46 | _site/tips/optimized-site.html
47 | _site/tips/url-filters-in-templates.html
48 | ```
49 |
50 | #### Prerequisites
51 |
52 | * The physical files should reside inside sub-folders that match the desired locale. For example, to "localize" a post at path
53 | `movies/_posts/2018-09-24-hello.markdown` with locale `fr`, you should create the physical copy at path
54 | `_locales/fr/movies/_posts/2018-09-24-hello.markdown`.
55 |
56 | * The file path of *an original page* relative to the *site's source*, should match the file path of the corresponding *locale
57 | page* relative to the `localization.content_dir` config value.
58 |
59 | This means that the locale page which would correspond to *an original page* `about.md` will be **`_locales/fr/about.md`**
60 | instead of **`_locales/fr/apropos.md`**. To force the locale page to render into a different url, you'll need to either
61 | explicitly set a `permalink` key or a `slug` key in the locale page's front matter.
62 |
63 | * **Files must exist in the default language.**
64 |
65 | The file `_locales/fr/about.md` will be **read** if and only if the file `about.md` exists.
66 |
--------------------------------------------------------------------------------
/docs/_docs/usage/advanced-usage.md:
--------------------------------------------------------------------------------
1 | ---
2 | permalink: /usage/advanced/
3 | ---
4 |
5 | ## Configuring Locale Metadata
6 |
7 |
8 |
9 |
10 |
11 | Adapted from a
12 |
13 | suggestion by @letrastudio
14 |
15 |
16 |
17 |
18 |
19 | The default metadata for every locale configured via the `locales_set` array is simply an `id` referencing the locale name.
20 | However, you may define custom metadata for your locales by slightly altering the `locales_set` setting:
21 |
22 | ```yaml
23 | localization:
24 | locale: en-US
25 | locales_set:
26 | en-US:
27 | label: English
28 | dir: ltr
29 | img: /assets/img/en-US.png
30 | fr-FR:
31 | label: Francais
32 | dir: ltr
33 | img: /assets/img/fr_FR.jpg
34 | ```
35 |
36 | *The metadata keys and values may be whatever your want it to be. It is not validated by the plugin.
37 | However, you will not be able to change the `id` attribute.*
38 |
39 | Once configured properly, you will be able to reference them via `{% raw %}{{ page.locale }}{% endraw %}` in your templates:
40 |
41 | ```html
42 | {%- raw -%}
43 |
44 |
45 |
46 | {% endraw %}
47 | ```
48 |
49 | ## Setting up hreflangs
50 |
51 | Each generated locale page is aware of its canonical page and its sibling locale page (for sites rendering three or more locales)
52 | and can be used to render meta tags for optimal SEO.
53 |
54 | Adding the following Liquid construct inside your `
17 |
18 |
101 | {%- if page.locale_siblings == empty %}
102 |
103 |
104 | This Page has no other versions
105 | {%- if site.localization.mode == 'auto' -%}
106 | as this page has been explicitly listed under the `exclude_set`
107 | {%- endif -%}.
108 |
109 |
110 | {%- else -%}
111 |
112 | {{ locale.available_locales }}:
113 |
114 | {%- for ref in page.locale_siblings %}
115 |
` tag will render the markup that tells the crawler how the pages are
55 | related to each other:
56 |
57 | ```html
58 | {% raw %}{% for item in page.hreflangs %}
59 |
60 | {% endfor %}{% endraw %}
61 | ```
62 |
63 | For example, `about.md` page with `permalink: /about/` in a site setup to render for locales `["en-US", "es", "fr"]` with `en-US`
64 | as the default locale and hosted at `http://example.com` will render with the following hreflangs:
65 |
66 | ```html
67 |
68 |
69 |
70 | ```
71 | Likewise, each of the *localized version* of the About page will also render with the **same hreflangs set as above**.
72 |
73 |
74 | ## Setting up a Locale Switcher
75 |
76 | Since hreflang data includes a self-referencing entry, iterating through `page.hreflangs` will result in a confusing linkset.
77 | Instead a subset of the hreflang data is available as `page.locale_siblings`:
78 |
79 | ```html
80 |
81 | {% raw %}{% for ref in page.locale_siblings %}
82 |
100 | ```
101 |
--------------------------------------------------------------------------------
/docs/_docs/usage/usage.md:
--------------------------------------------------------------------------------
1 | ---
2 | permalink: /usage/intro/
3 | ---
4 |
5 | The plugin does not literally translate content. However, it provides the means to output site content in multiple locales and
6 | languages by leveraging the versatility of Jekyll's Data files.
7 |
8 | ## Locale Data Files
9 |
10 | Data files for defining locales should reside in the directory configured as `localization.data_dir` (*Default: `locales`*) which
11 | in turn should reside in the site's `data_dir` (*Default: `_data`*).
12 | In other words, the default locale data directory is at `./_data/locales`.
13 | Data files can be of any format supported by Jekyll but should be named according to the configured locales.
14 |
15 | **NOTE: Top-level keys are stored internally as case-sensitive "underscore-delimited strings". This means that
16 | `_data/locales/en-US.yml` and `_data/locales/en_US.yml` map to the same locale `en-US`.**
17 |
18 | ## Templating
19 |
20 | A Liquid object `{% raw %}{{ locale }}{% endraw %}` serves as the main interface to this plugin. Technically, this object acts as
21 | an alias for the following:
22 |
23 | ```html
24 | {%- raw -%}
25 | {% assign current_locale = 'fr' %}
26 | {{ site.data.locales[current_locale] }}
27 | {% endraw %}
28 | ```
29 | The plugin sets the "*current locale*" attribute under the hood, automatically in sync with the current page's locale.
30 | Consequently allowing one to *simplify their Liquid templates*:
31 |
32 | ```html
33 | {%- raw -%}
34 | {{ locale.foo_bar }}
35 | {% endraw %}
36 | ```
37 |
38 | Apart from the `{% raw %}{{ locale }}{% endraw %}` object, the plugin also provides some filters to further ease Liquid
39 | templating.
40 |
--------------------------------------------------------------------------------
/docs/_layouts/default.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |