Comments (16)
Okay, looks like in the page template there has to be written:
---
language: <%= language %>
---
However, doing this will lead to this warning: Warning: Maximum call stack size exceeded
from grunt-assemble-i18n.
@rauberdaniel language is already there in page context, you can use it in your template with {{language}}
.
Additionally you can use i18n
helper in template with {{i18n "key"}}
as defined in the language file.
from grunt-assemble-i18n.
I’ve also tried that. So for example if my page template looks like this:
---
title: SomeTitle
---
<article>
<h2>{{i18n "title"}}</h2>
</article>
it will lead to Warning: The 'language' parameter is not defined
from grunt-assemble-i18n.
@doowb believe we also have a bug here with Warning: Maximum call stack size exceeded
while defining language
in front matter, it should fail more gracefully.
from grunt-assemble-i18n.
@rauberdaniel for that you should just go {{title}}
as it has nothing to do with i18n
functionality.
You need to have languages listed in either i18n.yml
or i18n.json
, take a look at the Gruntfile and test/fixtures
of this project. It'll sort you out. Please also see existing tickets and Pull Requests on things that are under development. The module is not feature-complete.
If you'd like to have a title from the translation file, the feature is currently pending on #33. You're welcome to vote for it ;)
Other than that I think we can close this ticket.
from grunt-assemble-i18n.
Sorry, there was some misunderstanding.
That title there has nothing to do with the title, I really want to show. So my template actually looks like this:
<article>
<h2>{{i18n "title"}}</h2>
</article>
Also, the i18n.json, de.json and en.json are included in the data
parameter.
i18n.json looks like this:
{
"languages": ["en","de"]
}
and the en/de.json files like this:
{
"lang": "en",
"title": "i18n - English",
}
from grunt-assemble-i18n.
Your example should work nicely, I don't see a problem, it must be related to Gruntfile, if it doesn't work.
from grunt-assemble-i18n.
There's some confusion here between the plugin and the helper.
TLDR; Just try using
{{title}}
to get the propertitle
property for the selected language.
Read on for a more detailed explaination 😀
The error you're receiving is from using the helper: {{i18n "title"}}
because it's looking for a language
parameter to be either in the helper hash: {{i18n "title" language="en"}}
or in the context wrapping the helper (which I thought it would be since it's in the page data).
Here's the specific code from the helper causing the issue.
As @jonschlinkert has pointed out, having the plugin and the helper in 2 different places is causing confusion, so we're working on ways to allow plugins to register helpers so all their logic can be encapsulated and documented together.
@rauberdaniel as you mentioned in #34 the documentation needs to be finished, but the point of this plugin was to generate pages specifically for each language and use the data from the language specific data file. This would allow you to use 1 template and do something as simple as {{title}}
to get the language specific title. The i18n helper was intended to do something similar but it was more verbose and required data to be setup in another way. I think after some work for merging these into the same project, the helper will use the same data objects as the plugin, allowing you to choose another language than the one specified in the page. Hopefully this will solve some of these issues.
from grunt-assemble-i18n.
@rauberdaniel is this on GitHub? I can probably get it working for you. Additionally, you can look at what we are doing.
https://github.com/wet-boew/wet-boew/blob/v4.0/Gruntfile.coffee#L309-L337
from grunt-assemble-i18n.
@LaurentGoderre Thanks, but it isn’t on GitHub. However, I found a way to get a result that is working for me. I created two assemble tasks for now (one for each language) and set the langauge explicitly.
Advantage for me: files aren’t called index-en.html
, but I have two folder en/
and de/
now which both contain the same file structure with files called index.html
etc.
from grunt-assemble-i18n.
That use case is covered using the permalinks plugin. @ain is using doing this I believe. You don't need separate tasks
from grunt-assemble-i18n.
I believe this would work
assemble: {
pages: {
options: {
flatten: true,
assets: '<%= config.dist %>/assets',
layoutdir: '<%= config.src %>/templates/layouts',
layout: 'default.hbs',
data: '<%= config.src %>/data/*/*.{json,yml}',
partials: '<%= config.src %>/templates/partials/*.hbs',
plugins: ['assemble-contrib-i18n','assemble-contrib-permalinks','assemble-contrib-sitemap'],
i18n: {
languages: ["en", "es"]
templates: ['<%= config.src %>/templates/pages/*.hbs']
},
permalinks: {
structure: ':language/index.html'
}
},
dest: '<%= config.dist %>/',
src: '!*.*',
}
},
// Before generating any new files,
// remove any previously-created files.
clean: ['<%= config.dist %>/**/*.{html,xml}']
});
from grunt-assemble-i18n.
Yes I'm using it in a similar fashion, except for the permalinks structure that is :language/:section/:slug:ext
for me.
from grunt-assemble-i18n.
@rauberdaniel just for a little background on this plugin, it was started as an example of how to do i18n things and some of the techniques evolved from there. There isn't that much built into this plugin because we found that the permalinks plugin solves many of the issues.
from grunt-assemble-i18n.
Can we close this issue?
from grunt-assemble-i18n.
I'd suggest to close this as well. We've discussed this before and emphasised the responsibilities of different middleware packages. We definitely don't want to have clutter or major overlaps across the assemble packages.
from grunt-assemble-i18n.
Related Issues (20)
- "with-plugin" task fails: No source files found HOT 2
- Add documentation HOT 30
- Stack overflow on language in front matter HOT 4
- Out of memory on compilation HOT 26
- Keep folder structure inside language folder? HOT 4
- Complementary plugin (shameless plug :P) HOT 2
- Convert to assemble v0.6.0 HOT 2
- Suggestion: make replacement of page file name optional HOT 18
- Duplicate Navigation generated in within partials HOT 4
- v0.1.3
- README.md cannot be generated using Verb HOT 4
- Allow language files to be divided or data to be nested HOT 6
- language not being set HOT 7
- i18n navigation HOT 6
- arrays and front-matter variables HOT 9
- problem with translation strings for pages HOT 6
- Moving to `grunt-assemble-i18n` HOT 2
- `i18n` helper inside `each` helper results in: The 'language' parameter is not defined HOT 16
- moderate severity security vulnerability on handlebars dependency HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-assemble-i18n.