WICG / proposals

A home for well-formed proposed incubations for the web platform. All proposals welcome.
https://wicg.io/
Other
233 stars 16 forks source link

i18n,l10n general solution proposal #161

Open calidion opened 4 months ago

calidion commented 4 months ago

Introduction

Currently, i18n and l10n is not easy and mature for web applications or sites. It can cause a lot efforts for both server side and frontend developers. And still it can be a big challenge .

I would like to suggest cerntain ways to solve this problem generally by browsers.

my suggestions are simple.

HTML part

define i18n resource with tag

it can define:

  1. orignized folders. <i18n url="./i18n"/>

  2. orginized resources like images, strings, etc. `

  3. the browsers should be able to enumerate how many languages are supported by this application/site or it can be described like this:

    <i18n locales=["en", "zh", "fr", "jp"]></i18n>

    use resource locally with tag.

it can be used like this:

Hello world! 你好, 世界!

add a tag` to define i18n resources for the web applications/sites. ### JS API part 1. add `i18n` and `l10n` objects 2. `i18n` provides apis: `i18n`.`hasLocale` which returns `["en", "zh", "fr", "jp"']` `i18n`.`getLocale` returns a `l10n` object, `null` if not supported `i18n`.`setLocale` set new locale for current web application/site 3. `l10n` provides apis: `l10n`.`format` formats a string with parameters `l10n`.`get` get an object by an id or an indexable string ``` l10n.get("image-id", "image") l10n.format("hello :name", {name: l10n.get("name-id", "string")}); ``` ### Browser side Browsers should be able to fetch all i18n resource indicated by the tags on the first load and every update. ## Feedback