Coder Social home page Coder Social logo

Comments (16)

rauberdaniel avatar rauberdaniel commented on June 9, 2024

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.

ain avatar ain commented on June 9, 2024

@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.

rauberdaniel avatar rauberdaniel commented on June 9, 2024

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.

ain avatar ain commented on June 9, 2024

@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.

ain avatar ain commented on June 9, 2024

@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.

rauberdaniel avatar rauberdaniel commented on June 9, 2024

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.

ain avatar ain commented on June 9, 2024

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.

doowb avatar doowb commented on June 9, 2024

There's some confusion here between the plugin and the helper.

TLDR; Just try using {{title}} to get the proper title 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.

LaurentGoderre avatar LaurentGoderre commented on June 9, 2024

@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.

rauberdaniel avatar rauberdaniel commented on June 9, 2024

@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.

LaurentGoderre avatar LaurentGoderre commented on June 9, 2024

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.

LaurentGoderre avatar LaurentGoderre commented on June 9, 2024

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.

ain avatar ain commented on June 9, 2024

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.

doowb avatar doowb commented on June 9, 2024

@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.

LaurentGoderre avatar LaurentGoderre commented on June 9, 2024

Can we close this issue?

from grunt-assemble-i18n.

ain avatar ain commented on June 9, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.