Skip to content
On this page

I18n

  • If you just need to use one language other than en:
Vue
ts
// in main.{js,ts} file
import { createApp } from "vue";
import App from "./App.vue";
import type { IConfig } from "@agufaui/vue";
import { Config, zhCn, Theme, CConfigProvideName } from "@agufaui/vue";

const app = createApp(App);

app.provide<IConfig>(
	CConfigProvideName,
	new Config({
		locale: "zh-cn",
		locales: [zhCn],
		baseTheme: Theme,
		theme: {
      ...
		},
	})
);

...
Svelte
ts
// in main.{js,ts} file
import { configStore } from "@agufaui/svelte";
import { Config } from "@agufaui/config";
import { Theme } from "@agufaui/theme";
import { zhCn } from "@agufaui/locale";

configStore.set(
	new Config({
		locale: "zh-cn",
		locales: [zhCn],
		baseTheme: Theme,
    theme: { ... }
	})
);

...
  • If you need to use more than one language:
Vue
ts
// in main.{js,ts} file
import { createApp, ref } from "vue";
import App from "./App.vue";
import type { IConfig } from "@agufaui/vue";
import { Config, en, zhCn, Theme, CConfigProvideName } from "@agufaui/vue";

const app = createApp(App);

app.provide<IConfig>(
	CConfigProvideName,
	new Config({
		locale: ref<string>("en"),
		locales: [en, zhCn],
		baseTheme: Theme,
		theme: {
      ...
		},
	})
);

...

then

ts
// in .vue file that toggles languages
<script setup lang="ts">
import { isRef, inject } from "vue";
import type { IConfig } from "@agufaui/vue";
import { CConfigProvideName } from "@agufaui/vue";

const config = inject<IConfig>(CConfigProvideName);

const click = () => {
	const locale = config?.locale;
	if (isRef(locale)) {
		if (locale.value === "en") {
			locale.value = "zh-cn";
		} else {
			locale.value = "en";
		}
	}
};
</script>
Svelte
ts
// in main.{js,ts} file
import { configStore } from "@agufaui/svelte";
import { Config } from "@agufaui/config";
import { Theme } from "@agufaui/theme";
import { en, zhCn } from "@agufaui/locale";
import { writable } from "svelte/store";

configStore.set(
	new Config({
		locale: writable<string>("en"),
		locales: [en, zhCn],
		baseTheme: Theme,
    theme: { ... }
	})
);

...

then

ts
// in .svelte file that toggles languages
<script lang="ts">
import type { Writable } from "svelte/store";
import { get } from "svelte/store";
import { configStore } from "@agufaui/svelte";

const click = () => {
  const locale = $configStore.locale as Writable<string>;
  if (get(locale) === "en") {
    locale.set("zh-cn");
  } else {
    locale.set("en");
  }
  // this line is important
  configStore.set($configStore);
};
</script>

configStore.set($configStore); line is important because in Svelte, you have to do a reassignment for Object to trigger update event, just update part of the Object won't trigger update event.

  • For language code that has hyphen, just use camel case when importing language file, for example, for zh-cn, use import { zhCn } from "@agufaui/locale"

109 Supported Languages

  • Afrikaans (af)
  • Albanian (sq)
  • Amharic (am)
  • Arabic (ar)
  • Armenian (hy)
  • Azerbaijani (az)
  • Basque (eu)
  • Belarusian (be)
  • Bengali (bn)
  • Bosnian (bs)
  • Bulgarian (bg)
  • Catalan (ca)
  • Cebuano (ceb)
  • Chichewa (ny)
  • Chinese Simplified (zh-cn)
  • Chinese Traditional (zh-tw)
  • Corsican (co)
  • Croatian (hr)
  • Czech (cs)
  • Danish (da)
  • Dutch (nl)
  • English (en)
  • Esperanto (eo)
  • Estonian (et)
  • Filipino (tl)
  • Finnish (fi)
  • French (fr)
  • Frisian (fy)
  • Galician (gl)
  • Georgian (ka)
  • German (de)
  • Greek (el)
  • Gujarati (gu)
  • Haitian Creole (ht)
  • Hausa (ha)
  • Hawaiian (haw)
  • Hebrew (he)
  • Hindi (hi)
  • Hmong (hmn)
  • Hungarian (hu)
  • Icelandic (is)
  • Igbo (ig)
  • Indonesian (id)
  • Irish (ga)
  • Italian (it)
  • Japanese (ja)
  • Javanese (jw)
  • Kannada (kn)
  • Kazakh (kk)
  • Khmer (km)
  • Kinyarwanda (rw)
  • Korean (ko)
  • Kurdish (Kurmanji) (ku)
  • Kyrgyz (ky)
  • Lao (lo)
  • Latin (la)
  • Latvian (lv)
  • Lithuanian (lt)
  • Luxembourgish (lb)
  • Macedonian (mk)
  • Malagasy (mg)
  • Malay (ms)
  • Malayalam (ml)
  • Maltese (mt)
  • Maori (mi)
  • Marathi (mr)
  • Mongolian (mn)
  • Myanmar (Burmese) (my)
  • Nepali (ne)
  • Norwegian (no)
  • Odia (or)
  • Pashto (ps)
  • Persian (fa)
  • Polish (pl)
  • Portuguese (pt)
  • Punjabi (pa)
  • Romanian (ro)
  • Russian (ru)
  • Samoan (sm)
  • Scots Gaelic (gd)
  • Serbian (sr)
  • Sesotho (st)
  • Shona (sn)
  • Sindhi (sd)
  • Sinhala (si)
  • Slovak (sk)
  • Slovenian (sl)
  • Somali (so)
  • Spanish (es)
  • Sundanese (su)
  • Swahili (sw)
  • Swedish (sv)
  • Tajik (tg)
  • Tamil (ta)
  • Tatar (tt)
  • Telugu (te)
  • Thai (th)
  • Turkish (tr)
  • Turkmen (tk)
  • Ukrainian (uk)
  • Urdu (ur)
  • Uyghur (ug)
  • Uzbek (uz)
  • Vietnamese (vi)
  • Welsh (cy)
  • Xhosa (xh)
  • Yiddish (yi)
  • Yoruba (yo)
  • Zulu (zu)

Released under the MIT License.