Using AirPower i18n Module for Frontend Internationalization with TypeScript
This tutorial demonstrates how to install the AirPower package, create a custom i18n class, add default and English language packs, register languages, and use type‑safe i18n tags in a Vue3 frontend, while also outlining the broader AirPower ecosystem and future plans.
The article introduces the AirPower i18n module, a TypeScript‑based solution for front‑end internationalization that avoids magic string values.
Installation
Install the package via npm, yarn, or pnpm:
npm install airpower
// or
yarn add airpower
// or
pnpm add airpowerImplement Default Language
Create a class extending AirI18n to define language texts, e.g., a GoodsName field for Chinese Simplified:
import { AirI18n } from 'airpower';
export class Languages extends AirI18n {
// language: AirLanguage.ChineseSimplified
GoodsName = '商品名称';
}Add New Language (English)
Define an English language pack by exporting a constant of type Languages with AirLanguage.English :
/**
* # English language pack
*/
export const English: Languages = {
language: AirLanguage.English,
GoodsName: "Goods name",
FileTooLarge: "File too large",
FileUnknownSize: "Invalid file size",
};Register Language and Set Current Language
Before the application starts, add the new language and set it as current:
// main.ts
Languages.addLanguage(English);
AirI18n.setCurrentLanguage(AirLanguage.English);
const app = createApp(App);
// ...Use i18n Tags in Templates
Replace magic string lookups with type‑safe property access:
<template>
{{ Languages.get().GoodsName }}
</template>
<script lang="ts" setup>
import { Languages } from '@/i18n/Languages';
</script>This approach provides IDE autocomplete, detects changes in language files, and eliminates reliance on third‑party plugins.
Ecosystem and Future Plans
AirPower includes utilities such as decorators, enum dictionaries, data transformation (similar to class-transformer ), date handling, encryption, and encoding. Additional packages like @airpower/core , @airpower/web , and upcoming @airpower/uniapp and @airpower/react extend functionality across platforms.
Conclusion
The guide shows how to leverage the AirPower i18n solution for clean, maintainable front‑end internationalization, encouraging readers to star, follow, and contribute to the open‑source project.
Rare Earth Juejin Tech Community
Juejin, a tech community that helps developers grow.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.