Skip to content

Latest commit

 

History

History
124 lines (99 loc) · 2.66 KB

README.md

File metadata and controls

124 lines (99 loc) · 2.66 KB

i18n

A WIP super small and incredibly fast localisation library with no documentation.

Goals

  1. Speed
  2. Small size
  3. Simplicity, durability, and maintainability
  4. Optional type-safety https://github.com/ivanhofer/typesafe-i18n
  5. Optional build step

Features

  • Simple JSON object input
  • Simple string/interpolation format
  • Pluralisation
  • In-code formatters
  • Bun for dev and TS testing

To-do

Notes

Crowdin

v3

current:

[
	"ns:circular_2",
    {
      "t": "This is two, ",
      "p": [
        [
          13,
          {
            "g": "$t", // v or g
            "d": {
              "k": "circular_1"
            }
          }
        ]
      ]
    }
]

proposed:

[
    "ns:circular_2",
	[
		{
			"t": "This is two, " // t, s, v, or g
		},
		{
        	"g": "$t",
        	"d": {
        	  "k": "circular_1"
        	}
        }
	]
]

Placeholder positions aren't needed.

// raw=true - return segments instead of string
[
	{ text: 'Hello' },
	{ slot: ['name', 'world'] }, // slots are omitted in non-raw (cooked..?) mode
	{ text: '!' }
]
// "Click {< here >} to {action} this {item}." // only works with 1 slot per string
// "Click {$slot(link, here)} to {action} this {item}." // not good, it's a valid getter
// "Click <{link} here> to {action} this {item}." // difficult
"Click {<link>here} to {action} this {item}." // conflicts with "don't translate inside placeholders"
"Click <link% here %> to {action} this {item}."
"Click {% link; here %} to {action} this {item}."

https://svelte.dev/docs/special-elements#slot

<I18n key="example" variables={{ action: 'restart', item: 'server' }} let:link>
	<a slot="link" class="font-bold" on:click={restart()}>{link}</a>
</I18n>
variable: Hello {name}
getter: I said "{$t(slot)}" # flatMap
slot: Please click <slot1% here %>  or <slot2% here %>