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

Translations not loading for Select elements #184

Closed
cabrerabywaters-zz opened this issue Sep 20, 2017 · 9 comments
Closed

Translations not loading for Select elements #184

cabrerabywaters-zz opened this issue Sep 20, 2017 · 9 comments

Comments

@cabrerabywaters-zz
Copy link

I'm trying to use the i18n translations to enable multiple languages on my forms.
All the components change the language correctly except for the Select and Resource components, that all the labels remain the same.

Is there something particular that we have to do to translate these components?

@cabrerabywaters-zz
Copy link
Author

Dear @travist ,
Any idea on this? than you.

Best Regards,
Ignacio

@cabrerabywaters-zz
Copy link
Author

Hello @travist, @douglaselee

Sorry to keep pushing with this one but its quite important for apps with multilanguage to be able to translate dropdown items.

Any update on this?

Regards!

@douglaselee
Copy link
Contributor

Hi @cabrerabywaters,

This would be a good thing and I've mentioned it before in formio/formio#422. Will try to look at it when time allows but can't predict when that will be.

@cabrerabywaters-zz
Copy link
Author

@douglaselee ,

What I'm doing now is that I have a "Translations" resource where I manage all the App's translations, then I load those into the FormioJs i18n object. It works perfectly for 90% of the elements.

Now I need to build this functionality for the Select elements of the App that I'm working with. I was thinking about just doing some "brute force" translation of the select elements after rendering, from the i18n object that translates all the rest of the forms, but as Select2 already has multilanguage functionality makes sense to just add it in Formiojs before rendering.

I'm not familiar with the Formiojs library, but if you could point me in the right direction I could try to do it directly on the library an not on my code.

@douglaselee
Copy link
Contributor

Hi @cabrerabywaters,

Maybe take a look at...

  /**
   * Translate a text using the i18n system.
   *
   * @param {string} text - The i18n identifier.
   * @param {Object} params - The i18n parameters to use for translation.
   */
  t(text, params) {
    params = params || {};
    params.component = this.component;
    params.nsSeparator = '::';
    params.keySeparator = '.|.';
    params.pluralSeparator = '._.';
    params.contextSeparator = '._.';
    return i18next.t(text, params);
  }

...in formiojs\src\components\base\Base.js and see how it's used in the repository. Good luck.

@cabrerabywaters-zz
Copy link
Author

@douglaselee,
What do you think about doing this? #262

Don't know if its the best approach but works fine for me.

@douglaselee
Copy link
Contributor

Hi @cabrerabywaters,

Looks good. Might be more efficient to consolidate 2 instances of this.itemTemplate(item).replace(/<\/?[^>]+(>|$)/g, "") into a single variable but no big deal.

Thanks for the assist!

@cabrerabywaters-zz
Copy link
Author

Hello @douglaselee,

Oh! sure! I just pushed the fix for that.
Hope it helps!

@douglaselee
Copy link
Contributor

Thanks again @cabrerabywaters, this will definitely help!

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