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

$te returns false if the key contains dot #1521

Open
5 tasks done
LasyIsLazy opened this issue Jul 4, 2022 · 10 comments
Open
5 tasks done

$te returns false if the key contains dot #1521

LasyIsLazy opened this issue Jul 4, 2022 · 10 comments
Labels
Status: Review Needed Request for review comments

Comments

@LasyIsLazy
Copy link

Reporting a bug?

If key has dot like a.b.c, $t('a.b.c') will get the correct result, but $te will return false.

Expected behavior

$te return true

Reproduction

{
   "a.b.c": "msg"
}

$t('a.b.c') return false

System Info

System:
    OS: macOS 12.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 88.95 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.16.1 - ~/.nvm/versions/node/v14.16.1/bin/node
    npm: 8.5.5 - ~/.nvm/versions/node/v14.16.1/bin/npm
  Browsers:
    Chrome: 103.0.5060.53
    Chrome Canary: 105.0.5152.0
    Firefox: 86.0.1
    Safari: 15.5
  npmPackages:
    @vue/cli-plugin-babel: ^4.5.15 => 4.5.15 
    @vue/cli-plugin-eslint: ^4.5.4 => 4.5.15 
    @vue/cli-plugin-typescript: ^4.5.4 => 4.5.15 
    @vue/cli-service: ^4.5.4 => 4.5.15 
    @vue/composition-api: ^1.4.9 => 1.5.0 
    vue: ^2.6.14 => 2.6.14 
    vue-class-component: ^7.2.3 => 7.2.6 
    vue-eslint-parser: ^8.0.1 => 8.0.1 
    vue-jest: 3.0.7 => 3.0.7 
    vue-property-decorator: ^9.1.2 => 9.1.2 
    vue-router: ^3.1.2 => 3.5.3 
    vue-template-compiler: ^2.6.11 => 2.6.14 
    vuex: ^3.4.0 => 3.6.2 
    vuex-class: ^0.3.2 => 0.3.2

Screenshot

No response

Additional context

No response

Validations

@LasyIsLazy LasyIsLazy added the Status: Review Needed Request for review comments label Jul 4, 2022
@domoratskii
Copy link

Hi! I have the same error. When using a dot in the key - te always returns false. Version ^9.2.0-beta.36.

@Kilbourne
Copy link

Same problem here. Please support it ( maybe just an option to choose the key separator)

@mkrajinov
Copy link

Same for me.

@cnguyen-de
Copy link

cnguyen-de commented Sep 28, 2022

same, had to remove $te check in the if before, was wondering why i18n didn't work after dependency update

@Yummy-zZ
Copy link

when my key is Chinese,it can't match.

@dmcknight26
Copy link

dmcknight26 commented Jul 21, 2023

Same issue - using this workaround for now...

import _ from 'lodash';

i18n.global.te = (key, locale) => {
  let effectiveLocale= !_.isEmpty(locale) ? locale : i18n.global.locale;
  let messages = i18n.global.messages[effectiveLocale];
  return Object.hasOwn(messages, key);
};

@Eternal-Rise
Copy link

Still not fixed :(

@MindaugasR
Copy link

MindaugasR commented Aug 30, 2023

@dmcknight26 solution works, some changes:

import { isEmpty } from 'lodash'

i18n.global.te = (key: string, locale: string) => {
  const effectiveLocale = !isEmpty(locale) ? locale : i18n.global.locale.value
  const messages = i18n.global.messages.value[effectiveLocale]
  return Object.hasOwn(messages, key)
}

@jclaveau
Copy link

jclaveau commented Nov 7, 2023

@dmcknight26 @MindaugasR

Thank you for your solution, here is the Typescript support (also without lodash dependency):

export const i18n = createI18n({
  locale: `fr-FR`,
  legacy: false,
  warnHtmlMessage: false,
  messages,
})

i18n.global.te = (key: Parameters<typeof i18n.global.te>[0], locale: Parameters<typeof i18n.global.te>[1]) => {
  const effectiveLocale = locale && locale.length ? locale : i18n.global.locale.value
  const messages = i18n.global.messages.value[effectiveLocale]
  return Object.hasOwn(messages, key)
}

@NamesMT
Copy link

NamesMT commented Jan 18, 2024

Bump, I'm using a flattened json for i18n,
For something like spotlight.title, using t('spotlight.title') works, but rt('@:spotlight.title') doesn't, weirdly inconsistent.


Refs for attention: intlify/vue-i18n-next#271

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Review Needed Request for review comments
Projects
None yet
Development

No branches or pull requests