middleman-transpath 0.0.1 β†’ 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62d93b69d638c1d6e6e80c37efe5950bcb99edc0
4
- data.tar.gz: 5e97daa8405d3a3a4a5d392b77d13258fee1094c
3
+ metadata.gz: c2f16960bde4558bb9f240f1d085a686ef03bcf8
4
+ data.tar.gz: 59a485d0749aebfabda6ae98b76878d6c0f32244
5
5
  SHA512:
6
- metadata.gz: 32c9f0fbc58124886d886e819cbf505efb9b41e947a801791cab08cdbc23c017cc6403a9a56db47b486ee592c376fa21dd5b8746e1692780b57bbea7cfcee489
7
- data.tar.gz: fee39ee94882d6777344355f11d31aaaf9e1716aa1fd21c6669578ca8ce8e3a4b5e2c9ce2b1f1356e3628af0d5d8a6c31da95a5c112fb15c98704b3e70e4c640
6
+ metadata.gz: 3d725bfef5f444c5e495cb9feee11c3816cce4b9f78e36c149ab7d4a099dd97a3e742a1387446b1ab23e1c81f608b037b149d5cf55fe043feb47ec0ccdde36dd
7
+ data.tar.gz: 116dd831464a68e117b8bd39fff2ace40e0c098f9411068a0b3c6bcf3063a5072fa37ae4cdd591e7d8c42c315a613d8bc173fa90049d8b70806d3875bca5a114
data/README.md CHANGED
@@ -6,26 +6,90 @@ Translating path with middleman, or access to the same page but different locale
6
6
 
7
7
  For example, you cannot access from :
8
8
 
9
- `projets/premier-projet` to `projects/first-project`
9
+ `/a-propos` to `/en/about`
10
+
11
+ ## Install
12
+ Add the following line to your **Gemfile**: `gem 'middleman-transpath'`
13
+ and this to your **config.rb**: `activate :transpath`
10
14
 
11
15
  ## Solution ?
12
- Yep, easily. Follow the steps :
13
- - Install and configure i18n with your favorite locales ! Presize your default locale too.
14
- - Then, generate a file named `languages.yml`, and configure how you want your languages links to be displayed. Here an example:
16
+ Yep, easily. Install and configure i18n with your favorite locales, and don't forget to specify your default locale (for example : `activate :i18n, :mount_at_root => :fr` in your **config.rb**, to use French as default locale), check the [documentation](https://middlemanapp.com/advanced/localization/)
15
17
 
16
- ```yaml
17
- fr: "πŸ‡«πŸ‡· - FR"
18
- en: "πŸ‡ΊπŸ‡Έ - EN"
18
+ ## Path configuration
19
+ Add a slug on your page [frontmatter](https://middlemanapp.com/basics/frontmatter/).
20
+ ```YAML
21
+ ---
22
+ slug: about
23
+ ---
19
24
  ```
20
25
 
21
- - Wow, such great, your links are displayed ! Now, let's configure paths in the next step.
26
+ Then, you'll need your locales files (**/locales/LANG\_SYMBOL.yml**). For each locale, you have to set, one by one (not in a list):
27
+ - The title translation in *titles*
28
+ - The slug translation in *paths*
22
29
 
23
- ## Path configuration
24
- Here is the most difficult part. You'll need your locales files (locales dir in the root folder). For each locale, you have to precise :
25
- - The title title of the page (identifier)
26
- - The title translation : in locale.titles
27
- - Subdirectories dir in a list (URL direction)
28
- - Subdirectories translation : in locale.paths (one by one, not a list)
30
+ ```YAML
31
+ titles:
32
+ about: 'A propos' # Page title
33
+ paths:
34
+ about: 'a-propos' # URL slug
35
+ ```
36
+
37
+ If you want to see an example, go to the [wiki section](https://github.com/bastienrobert/middleman-transpath/wiki/Locale-example)
38
+
39
+ ### Subdirectories
40
+ If you have subdirectories, like **/projects/project-one**, it's not a problem, set in your locales files:
41
+ ```YAML
42
+ paths:
43
+ projects: 'projects'
44
+ project-one: 'project-one'
45
+ ```
46
+
47
+ and on your page'frontmatter:
48
+ ```YAML
49
+ slug: project-one
50
+ dir:
51
+ - projects
52
+ ```
53
+
54
+ You need to add all slugs, even if it's not a page. For example if you have a page like /about/me, and about is not a page, you need to set a translation for about anyway.
55
+
56
+ ### Dynamic pages
57
+ When you generate dynamic pages using proxy, add `:data => { :slug => project.en.slug }`. You'll have to generate it on multiple languages like this:
58
+ ```RUBY
59
+ data.projects.each do |project|
60
+ proxy "/projets/#{project.fr.slug}/index.html", "templates/project.html", :locals => { :project => project }, :locale => :fr, :ignore => true, :data => { :slug => project.fr.slug }
61
+ proxy "en/projects/#{project.en.slug}/index.html", "templates/project.html", :locals => { :project => project }, :locale => :en, :ignore => true, :data => { :slug => project.en.slug }
62
+ end
63
+ ```
64
+
65
+ Then, the frontmatter config is a bit difficult:
66
+ ```YAML
67
+ ---
68
+ dynamic:
69
+ enable: true
70
+ data: project # The data you send using locals in your proxy
71
+ name: name # What you want to use for your page title (here: project.name)
72
+ slug: slug # What you want to use as slug (here: project.slug)
73
+ dir:
74
+ - projects # You'll can access through /projects/the-project-slug
75
+ ---
76
+ ```
77
+
78
+ The data in the data/projects.yml looks like this:
79
+ ```YAML
80
+ - fr:
81
+ name: Premier projet
82
+ slug: premier-projet
83
+ en:
84
+ name: First Project
85
+ slug: first-project
86
+ ```
87
+
88
+ ### AAAAAAH! I need a complete example!
89
+ Okok, just go here, to get everyting completely detailled:
90
+ - [Simple static page](https://github.com/bastienrobert/middleman-transpath/wiki/Simple-static-page)
91
+ - [Simple static with subfolder](https://github.com/bastienrobert/middleman-transpath/wiki/Simple-static-with-subfolder)
92
+ - [Dynamic page](https://github.com/bastienrobert/middleman-transpath/wiki/Dynamic-page)
29
93
 
30
94
  ## Helper to translate the current page
31
95
  Simply use the following helper to translate your current page in another language. Replace the **:fr** by the locale symbol of your choise.
@@ -33,8 +97,10 @@ Simply use the following helper to translate your current page in another langua
33
97
  <%= link_translate(:fr) %>
34
98
  ```
35
99
 
36
- ## Contributing
100
+ ## Helper to translate the page title
101
+ Add `title_translate` in your layout `<title>`. It'll use the title you specified in frontmatter, automaticly.
37
102
 
103
+ ## Contributing
38
104
  1. Fork it ( https://github.com/bastienrobert/middleman-transpath/fork )
39
105
  2. Create your feature branch (`git checkout -b my-new-feature`)
40
106
  3. Commit your changes (`git commit -am 'Add some feature'`)
@@ -4,12 +4,14 @@ require 'middleman-core'
4
4
  # Extension namespace
5
5
  class Transpath < ::Middleman::Extension
6
6
 
7
+ option :label, {en: 'πŸ‡ΊπŸ‡Έ - EN', fr: 'πŸ‡«πŸ‡· - FR'}, 'This hash should contain the lang symbol and his label'
8
+
7
9
  def initialize(app, options_hash={}, &block)
8
10
  super
9
11
  end
10
12
 
11
13
  helpers do
12
- def path_translate(lang)
14
+ def link_translate_path(lang)
13
15
  begin
14
16
  current_page.data.dir.map { |dir| t("paths.#{dir}", locale: lang, :default => dir) + '/'}.join('')
15
17
  rescue
@@ -17,22 +19,41 @@ class Transpath < ::Middleman::Extension
17
19
  end
18
20
  end
19
21
 
20
- def title_translate(lang)
21
- t("paths.#{current_page.data.title}", locale: lang, :default => current_page.data.title)
22
+ def link_translate_slug(lang)
23
+ dynamic = current_page.data.dynamic
24
+ unless (defined?(dynamic.enable)).nil?
25
+ current_page
26
+ .locals[dynamic.data.parameterize.underscore.to_sym][lang.to_s]
27
+ .send(dynamic.slug.to_s)
28
+ else
29
+ t("paths.#{current_page.data.slug}", locale: lang, :default => current_page.data.slug)
30
+ end
22
31
  end
23
32
 
24
- def link_translate(lang)
25
- return link_to data.languages.send(lang.to_s),
26
- if lang === I18n.default_locale
27
- config[:host] + '/' +
28
- path_translate(lang) +
29
- title_translate(lang)
33
+ def title_translate
34
+ dynamic = current_page.data.dynamic
35
+ unless (defined?(dynamic.enable)).nil?
36
+ current_page
37
+ .locals[dynamic.data.parameterize.underscore.to_sym][locale.to_s]
38
+ .send(dynamic.name.to_s)
39
+ .capitalize
30
40
  else
31
- config[:host] + '/' +
32
- lang.to_s + '/' +
33
- path_translate(lang) +
34
- title_translate(lang)
41
+ t("titles.#{current_page.data.slug}", locale: lang, :default => current_page.data.slug).capitalize
35
42
  end
36
43
  end
44
+
45
+ def link_translate(lang, params={})
46
+ return link_to (params[:label] ||= params['label'] ||= extensions[:transpath].options.label[lang]),
47
+ if lang === I18n.default_locale
48
+ config[:host] + '/' +
49
+ link_translate_path(lang) +
50
+ link_translate_slug(lang)
51
+ else
52
+ config[:host] + '/' +
53
+ lang.to_s + '/' +
54
+ link_translate_path(lang) +
55
+ link_translate_slug(lang)
56
+ end
57
+ end
37
58
  end
38
59
  end
Binary file
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "middleman-transpath"
6
- s.version = "0.0.1"
6
+ s.version = "0.0.2"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Bastien Robert"]
9
9
  # s.email = ["email@example.com"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-transpath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bastien Robert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-08 00:00:00.000000000 Z
11
+ date: 2017-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -40,6 +40,7 @@ files:
40
40
  - features/support/env.rb
41
41
  - lib/middleman-transpath.rb
42
42
  - lib/middleman-transpath/extension.rb
43
+ - middleman-transpath-0.0.1.gem
43
44
  - middleman-transpath.gemspec
44
45
  homepage:
45
46
  licenses: []