middleman-transpath 0.0.1 β 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +81 -15
- data/lib/middleman-transpath/extension.rb +34 -13
- data/middleman-transpath-0.0.1.gem +0 -0
- data/middleman-transpath.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2f16960bde4558bb9f240f1d085a686ef03bcf8
|
4
|
+
data.tar.gz: 59a485d0749aebfabda6ae98b76878d6c0f32244
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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.
|
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
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
##
|
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
|
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
|
21
|
-
|
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
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
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
|
data/middleman-transpath.gemspec
CHANGED
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.
|
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-
|
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: []
|