10.0.4 • Published 2 months ago

petite-vue-i18n v10.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

petite-vue-i18n

Small size subset of Vue I18n

petite-vue-i18n is an alternative distribution of Vue I18n, which provides only minimal features.

❓ What is the difference from Vue I18n ?

  • The Size is smaller than vue-i18n
    • CDN or without a Bundler
      • Package reduce size: runtime + compiler ~32%, runtime only ~45%
      • petite-vue-i18n: runtime + compiler ~9.61KB, runtime only ~5.51KB (production build, brotli compression)
      • vue-i18n: runtime + compiler ~14.18KB, runtime only ~10.12KB (production build, brotli compression)
    • ES Modules for browser
      • Package reduce size: runtime + compiler ~32%, runtime only ~45%
      • petite-vue-i18n: runtime + compiler ~10.51KB, runtime only ~6.20KB (production build, brotli compression)
      • vue-i18n: runtime + compiler ~15.40KB, runtime only ~11.12KB (production build, brotli compression)
    • Application bundle size
  • The legacy API is not supported, only the composition API
  • The APIs for the following DateTime Formats, Number Formats, and utilities aren’t included. Translation only
    • n, $n
    • d, $d
    • rt, $rt
    • tm, $tm
    • getDateTimeFormat, setDateTimeFormat, mergeDateTimeFormat
    • getNumberFormat, setNumberFormat, mergeNumberFormat
  • The only locale messages that can be handled are simple key-values. if you can handle hierarchical locale messages, you need to customize them using the API
  • The algorithm of local fallback is the array order specified in fallbackLocale
  • Custom directive v-t isn’t included
  • The following components provided by vue-i18n aren’t included
    • Translation i18n-t
    • DatetimeFormat i18n-d
    • NumberFormat i18n-n

🔨 The use case of petite-vue-i18n

vue-i18n includes various i18n features such as translation, datetimes format and number formats. Some projects may only use translation and not datetime formats. At the moment, even in that case, the code for that feature is included.

If your project only uses t or $t API for translation, so we recommended you would use petite-vue-i18n better than vue-i18n. And your project needs the features of vue-i18n, you can smoothly migrate from petite-vue-i18n to vue-i18n. This means that it’s progressive enhancement.

💿 Installation

Basically, it’s the same as installing vue-i18n. The only difference is that the part of URL or part of path are changed from vue-i18n to petite-vue-i18n.

CDN

You need to insert the following scripts to end of <head>:

<script src="https://unpkg.com/vue@next"></script>
<script src="https://unpkg.com/petite-vue-i18n"></script>

The following is the application code with the script tag:

<script>
const { createApp } = Vue
const { createI18n } = PetiteVueI18n

const i18n = createI18n({
  // something vue-i18n options here ...
})

const app = createApp({
  // something vue options here ...
})

app.use(i18n)
app.mount('#app')
</script>

Package managers

NPM:

npm install petite-vue-i18n --save

PNPM:

pnpm add petite-vue-i18n

Yarn:

yarn add petite-vue-i18n
import { createApp } from 'vue'
import { createI18n } from 'petite-vue-i18n'

const i18n = createI18n({
  // something vue-i18n options here ...
})

const app = createApp({
  // something vue options here ...
})

app.use(i18n)
app.mount('#app')

🚀 Usages

Hello world

Template:

<div id="app">
  <h1>{{ t('hello world') }}</h1>
</div>

Scripts:

const { createApp } = Vue
const { createI18n, useI18n } = PetiteVueI18n
// or for ES modules
// import { createApp } from 'vue'
// import { createI18n } from 'petite-vue-i18n'

const i18n = createI18n({
  locale: 'en',
  messages: {
    en: {
      'hello world': 'Hello world!'
    },
    ja: {
      'hello world': 'こんにちは、世界!'
    }
  }
})

// define App component
const App = {
  setup() {
    const { t } = useI18n()
    return { t }
  }
}

const app = createApp(App)

app.use(i18n)
app.mount('#app')

Use the same message resolver and locale fallbacker as vue-i18n

In petite-vue-i18n, the message resolver and locale fallbacker use simple implementations to optimize code size, as described in the differences section, as the belows:

  • message resolver
    • Resolves key-value style locale messages
    • About implementation, see the here
  • locale fallbacker
    • Fallback according to the array order specified in fallbackLocale
    • If a simple string locale is specified, fallback to that locale
    • About implementation, see the here

If you want to use the same message resolver and locale fallbacker as vue-i18n, you can change them using the API.

Note that at this time, only bundlers like vite and webpack are supported.

You need to install @intlify/core-base to your project with package manager.

npm install --save @intlify/core-base
# for pnpm
# pnpm add @intlify/core-base
# for yarn
# yarn add @intlify/core-base

Then, at the entry point of the application, configure the message resolver and locale fallbacker using the API as the below:

import { createApp } from 'vue'
import { createI18n } from 'petite-vue-i18n'
import {
  registerMessageResolver, // register the message resolver API
  resolveValue, // message resolver of vue-i18n which is used by default
  registerLocaleFallbacker, // register the locale fallbacker API
  fallbackWithLocaleChain // locale fallbacker of vue-i18n which is used by default
} from '@intlify/core-base'

// register message resolver of vue-i18n
registerMessageResolver(resolveValue)

// register locale fallbacker of vue-i18n
registerLocaleFallbacker(fallbackWithLocaleChain)

// some thing code ...
// ...

With the above settings, locale message resolving and locale fallbacking will be handled in the same way as in vue-i18n, note that the code size will increase slightly.

Switch without changing import ID

You can switch from vue-i18n to petite-vue-i18n in your application using npm alias without changing the import ID.

Package.json:

 {
   // ...
   "dependencies": {
     "vue": "^3.4.14",
-     "vue-i18n": "^10.0.0"
+     "vue-i18n": "npm:petite-vue-i18n@^10.0.0"
   },
 }

You need @intlify/unplugin-vue-i18n to build your application.

©️ License

MIT

10.0.0

2 months ago

10.0.1

2 months ago

10.0.2

2 months ago

10.0.3

2 months ago

10.0.4

2 months ago

10.0.0-rc.1

3 months ago

9.14.1

2 months ago

10.0.0-beta.6

3 months ago

9.14.0

3 months ago

10.0.0-beta.2

5 months ago

10.0.0-beta.3

4 months ago

10.0.0-beta.1

6 months ago

10.0.0-beta.4

4 months ago

10.0.0-beta.5

4 months ago

10.0.0-alpha.5

6 months ago

10.0.0-alpha.4

7 months ago

10.0.0-alpha.3

7 months ago

10.0.0-alpha.2

7 months ago

10.0.0-alpha.1

7 months ago

9.13.1

7 months ago

9.13.0

7 months ago

9.12.1

7 months ago

9.12.0

7 months ago

9.11.1

8 months ago

9.11.0

8 months ago

9.10.2

8 months ago

9.10.0

9 months ago

9.10.1

9 months ago

9.9.1

10 months ago

9.9.0

11 months ago

9.8.0

12 months ago

9.6.4

1 year ago

9.6.3

1 year ago

9.6.2

1 year ago

9.6.1

1 year ago

9.6.0

1 year ago

9.6.5

1 year ago

9.7.1

1 year ago

9.7.0

1 year ago

9.4.1

1 year ago

9.4.0

1 year ago

9.5.0

1 year ago

9.3.0

1 year ago

9.3.0-beta.21

1 year ago

9.3.0-beta.22

1 year ago

9.3.0-beta.23

1 year ago

9.3.0-beta.24

1 year ago

9.3.0-beta.25

1 year ago

9.3.0-beta.26

1 year ago

9.3.0-beta.27

1 year ago

9.3.0-beta.20

1 year ago

9.3.0-beta.17

2 years ago

9.3.0-beta.18

1 year ago

9.3.0-beta.19

1 year ago

9.3.0-beta.14

2 years ago

9.3.0-beta.15

2 years ago

9.3.0-beta.16

2 years ago

9.3.0-beta.9

2 years ago

9.3.0-beta.8

2 years ago

9.3.0-beta.7

2 years ago

9.3.0-beta.10

2 years ago

9.3.0-beta.11

2 years ago

9.3.0-beta.12

2 years ago

9.3.0-beta.13

2 years ago

9.3.0-beta.4

2 years ago

9.3.0-beta.3

2 years ago

9.3.0-beta.2

2 years ago

9.3.0-beta.1

2 years ago

9.3.0-beta.6

2 years ago

9.3.0-beta.5

2 years ago

9.3.0-beta.0

2 years ago

9.2.0-beta.38

2 years ago

9.2.0-beta.37

2 years ago

9.2.0-beta.39

2 years ago

9.2.2

2 years ago

9.2.0-beta.36

2 years ago

9.2.1

2 years ago

9.2.0

2 years ago

9.2.0-beta.40

2 years ago

9.2.0-beta.34

3 years ago

9.2.0-beta.33

3 years ago

9.2.0-beta.35

3 years ago

9.2.0-beta.32

3 years ago

9.2.0-beta.31

3 years ago

9.2.0-beta.30

3 years ago

9.2.0-beta.27

3 years ago

9.2.0-beta.26

3 years ago

9.2.0-beta.29

3 years ago

9.2.0-beta.28

3 years ago

9.2.0-beta.23

3 years ago

9.2.0-beta.25

3 years ago

9.2.0-beta.24

3 years ago

9.2.0-beta.18

3 years ago

9.2.0-beta.19

3 years ago

9.2.0-beta.22

3 years ago

9.2.0-beta.21

3 years ago

9.2.0-beta.20

3 years ago

9.2.0-beta.16

3 years ago

9.2.0-beta.17

3 years ago

9.2.0-beta.15

3 years ago

9.2.0-beta.14

3 years ago

9.2.0-beta.12

3 years ago

9.2.0-beta.13

3 years ago

9.2.0-beta.11

3 years ago

9.2.0-beta.10

3 years ago

9.2.0-beta.8

3 years ago

9.2.0-beta.9

3 years ago

9.2.0-beta.7

3 years ago

9.2.0-beta.6

3 years ago

9.2.0-beta.5

3 years ago

9.2.0-beta.4

3 years ago

9.2.0-beta.3

3 years ago

9.2.0-beta.2

3 years ago

9.2.0-beta.1

3 years ago

9.2.0-alpha.9

3 years ago

9.2.0-alpha.8

3 years ago

9.2.0-alpha.7

3 years ago