Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to setup a locale? #10

Closed
andreclemente opened this issue Oct 18, 2024 · 4 comments
Closed

How to setup a locale? #10

andreclemente opened this issue Oct 18, 2024 · 4 comments
Labels
question Further information is requested

Comments

@andreclemente
Copy link

What's the equivalent of this with nuxt-echarts?

import` { registerLocale } from 'echarts/core'
import langFR from '@/lang/echarts/langFR.js'
import langPT from '@/lang/echarts/langPT.js'

const locale = $env('APP_I18N_LOCALE').toUpperCase()
    switch (locale) {
      case 'FR':
        registerLocale('FR', langFR)
        break
      case 'PT':
        registerLocale('PT', langPT)
        break
      default:
        break
    }
  })
})
@kingyue737
Copy link
Owner

Just include what you posted in your source code.

You may also want to set this locale globally for echarts:

// app.vue
<script setup>
provide(INIT_OPTIONS_KEY,{locale})
</script>

@andreclemente
Copy link
Author

I fixed the error I was having on the build like this:

import * as echarts from 'echarts'
import langFR from '@/lang/echarts/langFR.js'
import langPT from '@/lang/echarts/langPT.js'

export default defineNuxtPlugin((nuxtApp) => {
  onNuxtReady(() => {
    const { $env } = nuxtApp
    const locale = $env('APP_I18N_LOCALE').toUpperCase()

    switch (locale) {
      case 'FR':
        echarts.registerLocale('FR', langFR)
        break
      case 'PT':
        echarts.registerLocale('PT', langPT)
        break
      default:
        break
    }
  })
})

@kingyue737
Copy link
Owner

Recommend

import { registerLocale } from 'echarts/core'

instead of

import * as echarts from 'echarts'
echarts.registerLocale()

The second one will include the whole echarts into the bundle.

@andreclemente
Copy link
Author

That throws an error when running the app with a build

@kingyue737 kingyue737 added the question Further information is requested label Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants