Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with translation strings for pages #59

Open
lhtdesignde opened this issue Aug 30, 2015 · 6 comments
Open

problem with translation strings for pages #59

lhtdesignde opened this issue Aug 30, 2015 · 6 comments

Comments

@lhtdesignde
Copy link

Hi guys,

i'm using this plugin quite heavily at the moment and am happy that it works for me almost 100%. So great work! I do have one compiling issue with the pages feature though.
I have around 8 pages which have a custom title. I'm generating the navigation out of the page titles:

{{#withSort pages "data.sortorder"}}
    {{#is data.language ../language}}
    <li class="nav-item item-{{this.basename}}{{#if this.isCurrentPage}} active{{/if}}">
        <a href="{{relative dest this.dest}}">{{ data.title }}</a>
    </li>
    {{/is}}
{{/withSort}}
title: '<%= i18n[language].H_I_02 %>'
layout: 'lyt-default.hbs'
description: 'press page'
sortorder: 3

in the json:

    "H_I_01": "FAQs",
    "H_I_02": "Press",
    "H_I_03": "Contact",
    "H_I_04": "Newsletter",

For around half of the pages the translation of the titles works but for some pages I get just the string rendered out into the navigation. So on some pages I get the following navigation:
FAQs | <%= i18n[language].H_I_02 %> | Contact | Newsletter OR
<%= i18n[language].H_I_01 %> | <%= i18n[language].H_I_02 %> | Contact | Newsletter

I'm not sure how this happened. All pages have the same implementation of the title string. Also weird that on the page itself the string is fine. So in this example above, if I'd click the weird string which is supposed to be press, the navigation shows correctly on the press page.

I tried to reduce the complexity of how the pages are rendered out (without sort, without url etc) but it's always the same result.

Do you have any idea what went wrong? In which area would I need to look, to fix this?

Thanks!

@LaurentGoderre
Copy link
Contributor

I encountered this too but I forgot how I solved it! The problem is that Assemble processes page in order and only do the replacements when rendering the page. What you are seeing is that the translation works for page that have been processed before that current page but the ones after have not yet been replaced.

@LaurentGoderre
Copy link
Contributor

Ok, so how I fixed this is I created a custom plugin registered on the render:pre:pages stage loops through all the page and perform the replacement manually for the title. It kinds of bypass this plugin just for titles.

@lhtdesignde
Copy link
Author

Do you maybe have an example of this custom plugin?

@LaurentGoderre
Copy link
Contributor

Here is the plugin I wrote for this:

/**
 * postprocess
 * @param  {Object}   params
 * @param  {Function} callback
 */

var async = require('async');
var _ = require('lodash');

var options = {
  stage: 'render:pre:pages'
};

module.exports = function (params, callback) {
  'use strict';

  var assemble       = params.assemble;
  var grunt          = params.grunt;

  var options        = assemble.options.permalinks;
  var pages          = assemble.options.pages;

  async.forEach(pages, function(page, next) {

    // TODO: traversal of the data object to expand more than just the title property
    page.data.title = _.template(page.data.title)(page.data);

    grunt.verbose.ok('Pre-processed:'.yellow, page.dest);
  });

  callback();
};

module.exports.options = options;

@lhtdesignde
Copy link
Author

sorry for the late answer. wasn't able to try it until now but this works. thank you!

@d-rogaczewski
Copy link

hey, i have the same problem but i don't know how to build this plugin. Do you can explain how i can use your plugin? would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants