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

Add localization for DOM elements #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

porst17
Copy link

@porst17 porst17 commented Nov 12, 2020

This allows to localize elements that are not currently attached to the DOM tree,
such as elements just created via document.createElement() or elements that are
managed by a third party library.

The use case is something like this:

const div = document.createElement('div');
div.setAttribute('data-i18n','the.key');
localize(div);

// later
parent.appendChild(div);

I have to admit that my changes are entirely untested. I just edited and commited directly on github. Hope it works anyway.

This allows to localize elements that are not currently attached to the DOM tree,
such as elements just created via document.createElement() or elements that are
managed by a third party library.
if(typeof selectorOrElements === 'string') {
// Assume query selector
elems = options.document.querySelectorAll(selectorOrElements);
} else if(Array.isArray(selectorOrElements)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be extended to support all kinds of iterable objects like NodeList etc.

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

Successfully merging this pull request may close these issues.

1 participant