tryggvigy / pseudo-localization

Dynamic pseudo-localization in the browser and nodejs
https://tryggvigy.github.io/pseudo-localization/hamlet.html
MIT License
140 stars 15 forks source link

Extract localize function #4

Closed azz closed 6 years ago

azz commented 6 years ago

I split it into two files so the localize function will be loadable in Node.js environments which don't have MutationObserver.

import { localize } from 'pseudo-localization';
// OR
import localize from 'pseudo-localization/localize';

console.log(localize('hello')); // --> ħḗḗŀŀǿǿ
console.log(localize('hello', { strategy: 'bidi' })); // --> ɥǝʅʅo‬

I noticed there's a copy of the script in the hamlet.html file, I didn't update that. I could change it to pull from unpkg and set up a Rollup UMD bundle if you'd like?

Closes #3

azz commented 6 years ago

If you want me to keep the change simple (and not support Node.js) I'm happy to do that 😄

tryggvigy commented 6 years ago

If you want me to keep the change simple (and not support Node.js) I'm happy to do that 😄

+1 for supporting node

I noticed there's a copy of the script in the hamlet.html file, I didn't update that. I could change it to pull from unpkg and set up a Rollup UMD bundle if you'd like?

Don't worry about that script. For now I think we should keep it simple and copy paste-able even at the cost of it going slightly out of sync.

tryggvigy commented 6 years ago

With the localize function exposed now it unlocks, like you mention in https://github.com/tryggvigy/pseudo-localization/issues/3 , to test that string actually are localised and not hard coded. I think there is value in explaining that use-case in the readme. Something similar to the snippet in #3. What do you think? I would do that in a follow up PR once I come up with some good copy.

tryggvigy commented 6 years ago

LGTM! I'll bump the version in package.json and publish.