jekyll-multiple-languages-plugin 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f3a2a500acf67ad5bea871232433bab2c4fee41366f0d59864e09256121eecf
4
- data.tar.gz: 2c9a1a596557ecd8aea38c07e0607d5e104e4c755b1f41c01fd14b9355d75f30
3
+ metadata.gz: 7d2f78a4cba9b1b00c236740a245bbc561cbf9740b330830a2464129ce44b818
4
+ data.tar.gz: 4efb2e419030c21a53ca1f3b38018bf31681a74e8c57fb4592ee375c6783a5e9
5
5
  SHA512:
6
- metadata.gz: f94a3062d46cbcfe28d878073e539ebf675494021e16d0bb96297878720a9c8b449f7d4a12b1d04bfc8a717178eb828bf7a15428842e5772412643099d5dbdfd
7
- data.tar.gz: 9e11ecf14870bbf6655d0ed407d83409ce87c57880e5ceac803d0236bc56c222b7d1af9cba901861edf23303b3db8a92dcdcc3ef50e3260dfde766a757f71c39
6
+ metadata.gz: 00f559010eec5ac54b67d651b8f77a06cc0004fc63a631aca402754dfc3b8b900fea14687c8b99f40c0156aef66146f70babdb9dd78d86b4ca9364268a80c629
7
+ data.tar.gz: 870ec29d2941d9f08be8c21e179703fa6ca58ec3b8c15f00ab663ab54e5b8501a02b5bea47a43a80c271e3d8450f20e839098b2971539d6c37879991c0493cb4
data/README.md CHANGED
@@ -38,6 +38,7 @@ Table of Contents
38
38
  - [5.5. Link between languages](#55-link-between-languages)
39
39
  - [5.6. Creating pages](#56-creating-pages)
40
40
  - [5.7. Creating posts](#57-creating-posts)
41
+ - [5.8. Select pages to translations](#58-select-pages-to-translations)
41
42
  - [6. License](#6-license)
42
43
  - [7. Example website](#7-example-website)
43
44
  - [7.1. Adding a new language](#71-adding-a-new-language)
@@ -359,6 +360,24 @@ Inside each of the language folders, you should create mirror pages to provide t
359
360
  ### 5.7. Creating posts
360
361
  There are no global posts. The posts are localized by language. And your posts will live in the `_i18n/[lang]/_posts` directory. So if, for example, you have English language on your website you should put your posts on `_i18n/en/_posts` directory.
361
362
 
363
+
364
+
365
+ ### 5.8. Select pages to translations
366
+
367
+ Sometimes you want to generate only selected versions of the page, especially excluding default language. You can do this using languages tag.
368
+
369
+ Example:
370
+ ```yaml
371
+ ---
372
+ permalink: /team/
373
+ permalink_fr: /equipe/
374
+
375
+ languages: ["fr"]
376
+ ---
377
+ ```
378
+
379
+ This generate only french version of the page.
380
+
362
381
  ## 6. License
363
382
 
364
383
  This project is available under the [MIT License](LICENSE.txt).
@@ -397,6 +416,8 @@ Then, create a file named `about.md` under `_i18n/en` with the English content.
397
416
 
398
417
 
399
418
  ## 8. Changelog
419
+ * 1.8.0
420
+ * I18n for site and Front Matter configurations [@pgoltsev](https://github.com/kurtsson/jekyll-multiple-languages-plugin/pull/125)
400
421
  * 1.7.0
401
422
  * Option to build the default language into a subfolder
402
423
  * Configurable verbosity
@@ -405,8 +426,8 @@ Then, create a file named `about.md` under `_i18n/en` with the English content.
405
426
  * 1.6.1
406
427
  * Improved testing
407
428
  * Support for Jekyll 4
408
- * Russian examples
409
- * Translations rebuilt every time page is reloaded in developer mode
429
+ * Russian examples
430
+ * Translations rebuilt every time page is reloaded in developer mode
410
431
  * 1.6.0
411
432
  * fix: check if static_file_r_path is set
412
433
  * Missing slash before lang prefix in lang picker example
@@ -425,8 +446,8 @@ Then, create a file named `about.md` under `_i18n/en` with the English content.
425
446
  * 1.4.1
426
447
  * Fixes a bug during site regeneration where translation paths were being nested based on wrongly set Jekyll variables.
427
448
  * 1.4.0
428
- * Support for Jekyll 3, thanks to [@pedrocarmona](https://github.com/screeninteraction/jekyll-multiple-languages-plugin/pull/62)
429
- * How to create pages documentation, thanks to [@elotroalex](https://github.com/screeninteraction/jekyll-multiple-languages-plugin/pull/57)
449
+ * Support for Jekyll 3, thanks to [@pedrocarmona](https://github.com/kurtsson/jekyll-multiple-languages-plugin/pull/62)
450
+ * How to create pages documentation, thanks to [@elotroalex](https://github.com/kurtsson/jekyll-multiple-languages-plugin/pull/57)
430
451
  * Many bug fixes
431
452
  * Code refactoring, cleanup and reorganization
432
453
  * Files and folders reorganization
@@ -434,8 +455,8 @@ Then, create a file named `about.md` under `_i18n/en` with the English content.
434
455
  * Improvements and fixes on documentations
435
456
  * Improved license files
436
457
  * 1.3.0
437
- * Support for localized links and custom permalinks, thanks to [@jasonlemay](https://github.com/screeninteraction/jekyll-multiple-languages-plugin/pull/53)
438
- * Support for excluding posts from translation, thanks to [@ctruelson](https://github.com/screeninteraction/jekyll-multiple-languages-plugin/pull/51)
458
+ * Support for localized links and custom permalinks, thanks to [@jasonlemay](https://github.com/kurtsson/jekyll-multiple-languages-plugin/pull/53)
459
+ * Support for excluding posts from translation, thanks to [@ctruelson](https://github.com/kurtsson/jekyll-multiple-languages-plugin/pull/51)
439
460
  * 1.2.9
440
461
  * Bug fix when excluding files from translation, again thanks to [@h6](https://github.com/H6)
441
462
  * 1.2.8
@@ -478,6 +499,7 @@ Then, create a file named `about.md` under `_i18n/en` with the English content.
478
499
  ### Contributors
479
500
  | User | Contribution |
480
501
  | :----------------------------------------------- | :----------------------------------- |
502
+ | [@pgoltsev](https://github.com/pgoltsev) | version 1.8.0
481
503
  | [@pedrocarmona](https://github.com/pedrocarmona) | support for Jekyll 3 |
482
504
  | [@elotroalex](https://github.com/elotroalex) | added a how to create page to README |
483
505
  | [@mohamnag](https://github.com/mohamnag) | permalink generation bug fix |
@@ -100,7 +100,17 @@ module Jekyll
100
100
 
101
101
  end
102
102
 
103
+ #*****************************************************************************
104
+ # :site, :pre_render hook
105
+ #*****************************************************************************
106
+ Jekyll::Hooks.register :site, :pre_render do |site, payload|
103
107
 
108
+ # Localize front matter data of every page.
109
+ #===========================================================================
110
+ (site.pages + site.documents).each do |item|
111
+ translate_props(item.data, site)
112
+ end
113
+ end
104
114
 
105
115
  ##############################################################################
106
116
  # class Site
@@ -167,6 +177,9 @@ module Jekyll
167
177
  self.config['lang'] = lang
168
178
  end
169
179
 
180
+ # Translate site attributes to current language
181
+ translate_props(self.config, self)
182
+
170
183
  puts "Building site for language: \"#{self.config['lang']}\" to: #{self.dest}"
171
184
 
172
185
  process_org
@@ -203,6 +216,26 @@ module Jekyll
203
216
 
204
217
 
205
218
 
219
+ ##############################################################################
220
+ # class PageReader
221
+ ##############################################################################
222
+ class PageReader
223
+ alias :read_org :read
224
+
225
+ #======================================
226
+ # read
227
+ #
228
+ # Monkey patched this method to remove excluded languages.
229
+ #======================================
230
+ def read(files)
231
+ read_org(files).reject do |page|
232
+ page.data['languages'] && !page.data['languages'].include?(site.config['lang'])
233
+ end
234
+ end
235
+ end
236
+
237
+
238
+
206
239
  ##############################################################################
207
240
  # class PostReader
208
241
  ##############################################################################
@@ -243,9 +276,11 @@ module Jekyll
243
276
 
244
277
  if site.config['relative_permalinks']
245
278
  File.join(@dir, data['permalink'])
246
- else
279
+ elsif site.config['lang']
247
280
  # Look if there's a permalink overwrite specified for this lang
248
- data['permalink_'+site.config['lang']] || data['permalink']
281
+ data['permalink_' + site.config['lang']] || data['permalink']
282
+ else
283
+ data['permalink']
249
284
  end
250
285
 
251
286
  end
@@ -367,6 +402,8 @@ module Jekyll
367
402
  puts "Using translation '%s' from default language: %s" %[translation, site.config['default_lang']]
368
403
  end
369
404
  end
405
+
406
+ TranslatedString.translate(key, lang, site)
370
407
 
371
408
  translation
372
409
  end
@@ -560,6 +597,86 @@ end
560
597
 
561
598
 
562
599
 
600
+ #======================================
601
+ # translate_key
602
+ #
603
+ # Translate given key to given language.
604
+ #======================================
605
+ def translate_key(key, lang, site)
606
+ unless site.parsed_translations.has_key?(lang)
607
+ puts "Loading translation from file #{site.source}/_i18n/#{lang}.yml"
608
+ site.parsed_translations[lang] = YAML.load_file("#{site.source}/_i18n/#{lang}.yml")
609
+ end
610
+
611
+ translation = site.parsed_translations[lang].access(key) if key.is_a?(String)
612
+
613
+ if translation.nil? or translation.empty?
614
+ translation = site.parsed_translations[site.config['default_lang']].access(key)
615
+
616
+ puts "Missing i18n key: #{lang}:#{key}"
617
+ puts "Using translation '%s' from default language: %s" %[translation, site.config['default_lang']]
618
+ end
619
+
620
+ translation
621
+ end
622
+
623
+
624
+ ################################################################################
625
+ # class TranslatedString
626
+ ################################################################################
627
+ class TranslatedString < String
628
+ #======================================
629
+ # initialize
630
+ #======================================
631
+ def initialize(*several_variants, key)
632
+ super(*several_variants)
633
+ @key = key
634
+ end
635
+
636
+ def key
637
+ @key
638
+ end
639
+
640
+ #======================================
641
+ # translate
642
+ #======================================
643
+ def self.translate(str, lang, site)
644
+ if str.is_a?(TranslatedString)
645
+ key = str.key
646
+ else
647
+ key = str
648
+ end
649
+ return TranslatedString.new(translate_key(key, lang, site), key = key)
650
+ end
651
+ end
652
+
653
+
654
+ #======================================
655
+ # translate_props
656
+ #
657
+ # Perform translation of properties defined in translation property list.
658
+ #======================================
659
+ def translate_props(data, site, props_key_name = 'translate_props')
660
+ lang = site.config['lang']
661
+ (data[props_key_name] || []).each do |prop_name|
662
+ if prop_name.is_a?(String)
663
+ prop_name = prop_name.strip
664
+ if prop_name.empty?
665
+ puts "There is an empty property defined in '#{props_key_name}'"
666
+ else
667
+ prop_value = data[prop_name]
668
+ if prop_value.is_a?(String) and !prop_value.empty?
669
+ data[prop_name] = TranslatedString.translate(prop_value, lang, site)
670
+ end
671
+ end
672
+ else
673
+ puts "Incorrect property name '#{prop_name}'. Must be a string"
674
+ end
675
+ end
676
+ end
677
+
678
+
679
+
563
680
  ################################################################################
564
681
  # Liquid tags definitions
565
682
 
@@ -1,6 +1,6 @@
1
1
  module Jekyll
2
2
  module MultipleLanguagesPlugin
3
- VERSION = "1.7.0"
3
+ VERSION = "1.8.0"
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,30 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-multiple-languages-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Kurtsson
8
8
  - Yonatan Miller
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-18 00:00:00.000000000 Z
12
+ date: 2022-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: bundler
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: 2.0.1
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: 2.0.1
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: html-proofer
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +78,7 @@ homepage: https://github.com/kurtsson/jekyll-multiple-languages-plugin/
92
78
  licenses:
93
79
  - MIT
94
80
  metadata: {}
95
- post_install_message:
81
+ post_install_message:
96
82
  rdoc_options:
97
83
  - "--charset=UTF-8"
98
84
  require_paths:
@@ -108,8 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
94
  - !ruby/object:Gem::Version
109
95
  version: '0'
110
96
  requirements: []
111
- rubygems_version: 3.0.3
112
- signing_key:
97
+ rubygems_version: 3.0.3.1
98
+ signing_key:
113
99
  specification_version: 4
114
100
  summary: I18n plugin for Jekyll
115
101
  test_files: []