react-fontpicker icon indicating copy to clipboard operation
react-fontpicker copied to clipboard

Support filter by language

Open vpckso opened this issue 11 months ago • 4 comments

Can support filter by language? Include subsets in fontInfo.json, then filter subsets by component props.

vpckso avatar Jan 14 '25 08:01 vpckso

Great issue for discussion!

I don't think it's documented anywhere, but I already considered internationalisation and decided not to tackle it.

Fonts supporting latin plus another writing system are currently supported if the client supports unicode-range: https://developers.google.com/fonts/docs/getting_started#specifying_script_subsets

So out of the box, you can already figure out which fonts are OK for your target language and use the existing options to display only those. But, the previewed font names are rendered in English.

This is the biggest challenge: that the font previews would need to be rendered in whatever target language.

Multi-language font previews cannot be practically bundled together, the English language npm package is already currently an astronomical 33 MB unpacked. (Which is why I offer the "lite" edition.)

So there would have to be a separate npm package for a fontpicker for each target language.

There would also need to be a translation file, mapping the English name (used by the code) to the target language in order to generate the previews.

Maybe something like:

/packages/fontpicker/translations/ja.json

{
	"Noto Sans JP": "Noto Sans JP",
	"Sawarabi Gothic": "さわらびゴシック",
	...
}

As the example above shows (courtesy of jimakuChan), native speakers don't even necessarily prefer to use their language to describe a certain font family. So each translation would really have to be done by a native speaker, for their own community.

If anyone is seriously interested in a version of react-fontpicker for their target language, feel free to submit a PR with the translation file. After that, I can take a stab at implementing alternative language support, and then publishing a version for that language. (This could take some time, and anyone is welcome to contribute here to speed up the process.)

ae9is avatar Jan 15 '25 10:01 ae9is

An easier alternative is to restrict your users to only fonts that support both Latin and your target writing system, if your users are OK with font names in English.

If anyone is interested in implementing that feature, I'm open to contributions from the community.

ae9is avatar Jan 15 '25 10:01 ae9is

https://github.com/ae9is/react-fontpicker/pull/75

vpckso avatar Jan 28 '25 06:01 vpckso

The easier alternative has now been implemented in #81, but leaving this issue open for a bit just in case anyone is seriously interested in adding true alternative language support!

ae9is avatar Feb 06 '25 13:02 ae9is