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

Use in DOM #90

Closed
nise opened this issue Aug 28, 2017 · 2 comments
Closed

Use in DOM #90

nise opened this issue Aug 28, 2017 · 2 comments

Comments

@nise
Copy link

nise commented Aug 28, 2017

Maybe I misunderstand the purpose of polyglot.js, but how can I address DOM-elements directly?
Lets say I have tag like <div id="foo"></div> that should contain the text "bar".

The jquery i18n library provides a way to use data-attributes like <div data-i18n=”foo”></div> in order to fill in the values for each key.

@ljharb
Copy link
Collaborator

ljharb commented Aug 28, 2017

This library doesn't solve those problems for you; you'd need to do the DOM interaction yourself.

@fabric-io-rodrigues
Copy link

Hi @nise, you can use jquery for help in the task, sample:

$('[data-i18n]').each(function () {
	var valueKey = $(this).data('i18n');
	if (valueKey != "") {
		var valueTranslate = polyglot.t(valueKey);
		$(this).html(valueTranslate);
	}
});

for more details: https://jsfiddle.net/fabriciorhs/hfqx92eq/

This PolyglotJS helps me a lot!

@ljharb ljharb closed this as completed Oct 7, 2017
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