File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ export const errorMessages: { [code: number]: string } = {
71
71
[ I18nErrorCodes . BRIDGE_SUPPORT_VUE_2_ONLY ] :
72
72
'vue-i18n-bridge support Vue 2.x only' ,
73
73
[ I18nErrorCodes . MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION ] :
74
- 'Must define ‘i18n’ option in Composition API with using local scope in Legacy API mode' ,
74
+ 'Must define ‘i18n’ option or custom block in Composition API with using local scope in Legacy API mode' ,
75
75
[ I18nErrorCodes . NOT_AVAILABLE_COMPOSITION_IN_LEGACY ] :
76
76
'Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly'
77
77
}
Original file line number Diff line number Diff line change @@ -1099,7 +1099,11 @@ function useI18nForLegacy(
1099
1099
const isLocale = scope === 'local'
1100
1100
const _composer = shallowRef < Composer | null > ( null )
1101
1101
1102
- if ( isLocale && instance . proxy && ! instance . proxy . $options . i18n ) {
1102
+ if (
1103
+ isLocale &&
1104
+ instance . proxy &&
1105
+ ! ( instance . proxy . $options . i18n || instance . proxy . $options . __i18n )
1106
+ ) {
1103
1107
throw createI18nError (
1104
1108
I18nErrorCodes . MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION
1105
1109
)
Original file line number Diff line number Diff line change @@ -525,6 +525,45 @@ describe('useI18n', () => {
525
525
expect ( html ( ) ) . toEqual ( '<p>en:world!</p>' )
526
526
} )
527
527
528
+ test ( 'use custom block' , async ( ) => {
529
+ const i18n = createI18n ( {
530
+ allowComposition : true ,
531
+ locale : 'ja' ,
532
+ messages : {
533
+ en : {
534
+ hello : 'hello!'
535
+ } ,
536
+ ja : { }
537
+ }
538
+ } )
539
+
540
+ const App = defineComponent ( {
541
+ setup ( ) {
542
+ const instance = getCurrentInstance ( )
543
+ if ( instance == null ) {
544
+ throw new Error ( )
545
+ }
546
+ const options = instance . type as ComponentOptions
547
+ options . __i18n = [
548
+ {
549
+ locale : 'ja' ,
550
+ resource : {
551
+ hello : 'こんにちは!'
552
+ }
553
+ }
554
+ ]
555
+ const { locale, t } = useI18n ( {
556
+ inheritLocale : true ,
557
+ useScope : 'local'
558
+ } )
559
+ return { locale, t }
560
+ } ,
561
+ template : `<p>{{ locale }}:{{ t('hello') }}</p>`
562
+ } )
563
+ const { html } = await mount ( App , i18n )
564
+ expect ( html ( ) ) . toEqual ( '<p>ja:こんにちは!</p>' )
565
+ } )
566
+
528
567
test ( 'not defined i18n option in local scope' , async ( ) => {
529
568
const i18n = createI18n ( {
530
569
allowComposition : true ,
You can’t perform that action at this time.
0 commit comments