Skip to content

Commit

Permalink
add pug function to wrap url with i18n path
Browse files Browse the repository at this point in the history
  • Loading branch information
zbryikt committed Jan 23, 2021
1 parent 7c23bfe commit 4a92d36
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ will access to `another-key` in `new-ns.yaml`. Be sure to add your namespace nam

"i18n": { ... "ns": ["default", "new-ns"] }

additionally, use `intlbase` to wrap path with a i18n based relative path:

a(href=intlbase('/faq'))


## TODO

Expand Down
11 changes: 10 additions & 1 deletion bin/lib/build/pug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/build/pug.ls
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require! <[fs fs-extra pug livescript stylus path js-yaml marked ./aux]>
require! <[fs path fs-extra pug livescript stylus path js-yaml marked ./aux]>

lc = {i18n: {}}
md-options = html: {breaks: true, renderer: new marked.Renderer!}
Expand Down Expand Up @@ -33,6 +33,7 @@ main = do
opt: (opt = {}) ->
if opt.i18n =>
pug-extapi.i18n = -> opt.i18n.t(it)
pug-extapi.intlbase = (p = "") -> if opt.i18n.language => path.join("/intl",opt.i18n.language,p) else p
pug-extapi.{}filters.i18n = (t, o) -> opt.i18n.t(t)
lc.i18n = opt.i18n
map: (list) ->
Expand Down
1 change: 1 addition & 0 deletions src/pug/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ html
i18n key filter
div= i18n("i18n key")
div= i18n("alternative:namespace-test")
div= intlbase("/")
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
div.textContent = "livescript filter test";</script><script type="application/json">{
"output": "lson test ok"
}
</script><div>i18n 翻譯測試 ( 編譯時期, pug filter )</div><div>i18n 翻譯測試 ( 執行時期, pug function )</div><div>命名域測試成功.</div></body></html>
</script><div>i18n 翻譯測試 ( 編譯時期, pug filter )</div><div>i18n 翻譯測試 ( 執行時期, pug function )</div><div>命名域測試成功.</div><div>/intl/zh-TW/</div></body></html>
2 changes: 1 addition & 1 deletion static/intl/en/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
div.textContent = "livescript filter test";</script><script type="application/json">{
"output": "lson test ok"
}
</script><div>i18n translation test ( compile time filter )</div><div>i18n translation test ( runtime function )</div><div>namespace test ok.</div></body></html>
</script><div>i18n translation test ( compile time filter )</div><div>i18n translation test ( runtime function )</div><div>namespace test ok.</div><div>/intl/en/</div></body></html>
2 changes: 1 addition & 1 deletion static/intl/zh-TW/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
div.textContent = "livescript filter test";</script><script type="application/json">{
"output": "lson test ok"
}
</script><div>i18n 翻譯測試 ( 編譯時期, pug filter )</div><div>i18n 翻譯測試 ( 執行時期, pug function )</div><div>命名域測試成功.</div></body></html>
</script><div>i18n 翻譯測試 ( 編譯時期, pug filter )</div><div>i18n 翻譯測試 ( 執行時期, pug function )</div><div>命名域測試成功.</div><div>/intl/zh-TW/</div></body></html>

0 comments on commit 4a92d36

Please sign in to comment.