meteor-autoform-i18n icon indicating copy to clipboard operation
meteor-autoform-i18n copied to clipboard

How to use this package inside another package?

Open derwaldgeist opened this issue 10 years ago • 6 comments
trafficstars

I'd like to use this package inside another package.

This is what I did:

  • Put the translation files inside an i18n folder inside the package folder
  • Included these JSON files via api.addFiles()
  • Attached the i18n JSON path via Schema.i18n('my.path'); in Meteor.startup()

However, the form is still in English. I am not using labels in the Schema itself, so this cannot be the root cause.

BTW: The term json_path in the documentation is a bit misleading. I tought it should be a path to the i18n files. I would like to recommend to rename it to something like json_key_path.

derwaldgeist avatar Sep 08 '15 11:09 derwaldgeist

After long time of debugging, I finally found out what my problem was:

I did not provide an English version for the form texts (en.i18n.json), because I thought I would not need this (as aldeed:autoform automatically generates English texts based on the SimpleSchema keys).

However, the implementation of autoform-i18n uses a call to TAPi18n.__() to detect which language keys are available on initialization (Schema.i18n()). At this point of time, TAPi18n uses the language that is used as the default language in the Meteor application, which is English for me. And since I did not provide an English JSON, no keys were returned.

The requirement to have an English JSON is a bit counter-intuitive and should definitely be mentioned in the documentation. I am also wondering why the keys are detected this way. Wouldn't it better to just rely on the information of the Schema itself?

derwaldgeist avatar Sep 08 '15 12:09 derwaldgeist

Hi there. I am trying to use this package inside my packages, but I couldn't make this work even with the english version being provided, as @derwaldgeist said. I followed the documentation to setup the Schema, without labels and placeholders in it, and then providing the "en" and "it" versions of them in the respective jsons. But even though I attached the json to the schema via the Schema.i18n api, I just see the plain version of the strings. No string from the json seem to be loaded. Any hint to head me to the right direction? Thanks in advance.

tobiaghiraldini avatar Oct 08 '15 07:10 tobiaghiraldini

Sometimes it helps if you add a file named package-tap.i18n to you project with the following content:

{
  "namespace": "project"
}

But beware to not include this file via api.addFiles() since this will break the app. I've actually never managed to use these namespaces as they are described in the tapi18n documentation. But adding the project namespace sometimes helped.

derwaldgeist avatar Oct 08 '15 08:10 derwaldgeist

I already had that file with the namespace in my package, thanks!! After I posted this comment I tried upgrading all the libraries (as I found I had some old version of them) and my issue seems resolved. Thank you @derwaldgeist for your quick feedback!

tobiaghiraldini avatar Oct 08 '15 08:10 tobiaghiraldini

Sorry for the late reply. You have to explicitely declare the languages you want available in your app by passing a "supported_languages" array in your app's "project-tap.i18n" json file.

See reference.

gwendall avatar Oct 08 '15 08:10 gwendall

@tobiaghiraldini: No problem. Oh yeah, the Meteor packaging system is quite weird, it only works if you add versions explicitly. I realized this after debugging a couple of hours since I could not understand why a package did not work as described in the docs. Until I found out that Meteor loaded a 0.0.2 version of it instead of a recent one.

derwaldgeist avatar Oct 08 '15 08:10 derwaldgeist