Nemo64 / meteor-translator

a feature rich internationalization (i18n) package for meteor with usage of the Unicode Common Locale Data Repository
MIT License
15 stars 4 forks source link

Rendering Translation Keys #4

Closed boustanihani closed 9 years ago

boustanihani commented 9 years ago

I noticed that the translation keys are rendered shortly before the translation occurs. This is really a matter of milliseconds (200ms - 400ms) but it doesn't look nice :(

There should be some way to prevent the templates from being rendered before the translation-data is fully loaded!!

Nemo64 commented 9 years ago

There is a method Translator#isLoading() which you could use for that.

<body>
{{#unless isLoading}}
{{> yield}}
{{/unless}}
</body>
UI.body.helpers({
  isLoading: function () {
    return FrontLang.isLoading()
  }
});

However that isn't a very nice solution imo. I could just return empty strings as long as the namespace is loading, what do you think?

boustanihani commented 9 years ago

Mmmh empty strings is better than keys I think :) but I preffer a way (kind of a global hook maybe) preventing any template from rendered (or setting it invisible) if it needs translations which still have not been loaded .. this would be perfect, I preffer to see nothing much more than seeing a form with visible input fields and missing labels!

I think this package should hook into the blaze-rendering-engine to achieve that, sadly I am a meteor beginner, but I would have loved to help extending your awesome work :)

Nemo64 commented 9 years ago

The translator now returns null when the translation isn't loaded yet. Blaze is intelligent enough to convert null into nothing in the template and it seems more clean than an empty string (although i thought about returning undefined).

I currently shy away from hooking into blaze mostly because:

  1. I have no idea how to do that properly
  2. I'm not sure if that is a good idea in the first place. It'll probably be better to find a way to load the translation faster. I currently think about wrapping the translation file with a jsonp approach and injecting a <script> into the html with the autodetected language in src. That way the browser could load it way earlier. This however also requires #3 to be done so nothing unneeded is loaded.