PlaidWeb / webmention.js

Client-side library for rendering webmentions from webmention.io
MIT License
112 stars 15 forks source link

i18n #23

Closed nekr0z closed 3 years ago

nekr0z commented 3 years ago

I understand it will be a lot of work, but are there any ideas about i18n?

fluffy-critter commented 3 years ago

i18n would be good but I have no idea what the ecosystem is like in the Javascript land. I'd like to prevent the library from getting too large (since it's intended to just be a single .js file that people plop onto their sites), and similarly I'd also like to avoid pulling in any dependencies which make it so that end users have to use npm if they want to do local modifications to the library.

For now my recommendation is that if you want to change the labels for your site's language, the easiest approach is to do local modifications on webmention.js yourself.

If someone were to design a thing that allows people to locally override the various strings (including the emojis used for the reaction images), I wouldn't turn it down.

nekr0z commented 3 years ago

I was thinking more about some kind of a CI/CD framework that would somehow "compile" webmention..min.js variants for each supported language for releases.

The thing is, simply translating the labels is not enough.

e.length+" Reaction"+(e.length>1?"s":"")

becomes

e.length+" реакци"+(((e.length%100>10&&e.length%100<15)||e.length%10>4)?"й":(e.length%10==1?"я":"и"))

in Russian, for example, because Russian numeral suffixes are funny that way...

fluffy-critter commented 3 years ago

Hm, yeah, that's why I'd like to defer it to a library that actually knows how to deal with things like that. :)

Having an npm build tool that builds webmention.ru.min.js and webmention.es.min.js and so on is a pretty good idea. I don't think that needs full CI/CD, though.

fluffy-critter commented 3 years ago

Oh, how about the idea of just not trying to pluralize contextually? Like, leaving off the number and just being like

<h1>Reactions</h1>

or

<h1>Реакции</h1>

regardless of the number? (Apologies if that's not the right way to form a generic plural in Russian, I obviously don't know the language.) These days I'm pretty against the idea of showing a numeric count anyway. And that would also make the l10n/i18n a lot easier.

nekr0z commented 3 years ago

Having an npm build tool that builds webmention.ru.min.js and webmention.es.min.js and so on is a pretty good idea. I don't think that needs full CI/CD, though.

I know absolutely nothing about the JS ecosystem and never touch npm if I can help it, so I trust your expertise on this one. ;)

fluffy-critter commented 3 years ago

I mean I actively try to avoid the JS ecosystem, myself, which is why I built this as a simple standalone library that tries to be compatible with older browsers and doesn't require an npm build to be used. :) I only do webdev as a hobby and there's a reason I like IndieWeb!

I didn't even write the npm stuff on webmention.js, that was just a contribution from someone else who wanted to use it that way and it didn't seem to cause any problems for me.

Ryuno-Ki commented 3 years ago

I work in Frontend development professionally :)

Hm, I think i18next is quite popular. You could load it from a CDN.

If you read the Getting Started guide, you'll see, that it's managed via a dictionary. I'd use the some kind of feature detection to not break if i18next couldn't be loaded:

if (typeof window.i18next === 'undefined') {
  window.i18next = {
    t: function (key) { return key; },
  };
}

Then, when using the text to translate as key, your library would return it as-is if i18next weren't loaded. If it is loaded, their library could kick in.

Your instruction would refer to let the web author implement the boilerplate code if required. WDYT?

fluffy-critter commented 3 years ago

I am extremely not a fan of requiring an external dependency from a CDN, but if it's easy enough to include it for the minify step it seems like an okay way to go.

Ryuno-Ki commented 3 years ago

You could as well self-host it :) (As do I)

fluffy-critter commented 3 years ago

Yes, of course, but I like keeping the installation of this as simple as possible. The less I have to document and the more it's just "add this one file and this one script tag," the better.

fluffy-critter commented 3 years ago

On further thought, as long as there's the automatic safe fallback and adding the library is optional, I'm fine with it requiring extra steps.

Ryuno-Ki commented 3 years ago

https://github.com/PlaidWeb/webmention.js/issues/23#issuecomment-812075847 would be the fallback to make the library optional :)

(I need to try it to double-check).

What would be the steps to draft a PR on this? It's been a while since my last time. Are you willing to accept one? I could imagine, that this repo could have a GitHub Page for testing purposes. One HTML page with i18n and another one without. Then people could webmention it from their domain.

fluffy-critter commented 3 years ago

I don't have any specific PR process. Just use your best judgement and I'll be sure to let you know if there's a problem. ;) Do run the minify step before submitting though.

And yeah the tests need to be a lot better. Currently I just have the local static files that do a smoke test with a few known blog entries with the things being tested. Someday this needs to be improved now that a lot of people are using my quick hack. :)

Ryuno-Ki commented 3 years ago

Ha! https://github.com/PlaidWeb/webmention.js/issues/23#issuecomment-812075847 almost worked :joy_cat:

24 provides i18next, but does not document, which strings got translatable.

What I haven't touched, however, is pluralising: https://www.i18next.com/translation-function/plurals For now, it got refactored into a separate function, so it should be easier to provide.

@nekr0z Do you have a need for pluralisation in your use case?

nekr0z commented 3 years ago

@nekr0z Do you have a need for pluralisation in your use case?

Not if pluralization is being removed anyway :)

Ryuno-Ki commented 3 years ago

@fluffy-critter reminded me on this outcome in the PR review. Dropped pluralisation now. A PR with updated documentation is already in review :)