diff --git a/src/main/java/tech/jhipster/lite/generator/client/react/i18n/domain/ReactI18nModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/client/react/i18n/domain/ReactI18nModuleFactory.java index c7043fcb28f..38a3bdd38fe 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/react/i18n/domain/ReactI18nModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/client/react/i18n/domain/ReactI18nModuleFactory.java @@ -11,8 +11,8 @@ public class ReactI18nModuleFactory { private static final JHipsterSource APP_SOURCE = from("client/react/i18n/src/main/webapp/app"); - private static final JHipsterSource ASSETS_FR_SOURCE = from("client/react/i18n/src/main/webapp/assets/locales/fr"); - private static final JHipsterSource ASSETS_EN_SOURCE = from("client/react/i18n/src/main/webapp/assets/locales/en"); + private static final JHipsterSource ASSETS_FR_SOURCE = from("client/react/src/main/webapp/assets/fr"); + private static final JHipsterSource ASSETS_EN_SOURCE = from("client/react/src/main/webapp/assets/en"); private static final String INDEX = "src/main/webapp/"; private static final String INDEX_TEST = "src/test/webapp/unit/common/primary/app/"; diff --git a/src/main/java/tech/jhipster/lite/generator/client/react/i18n/infrastructure/primary/ReactI18nModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/client/react/i18n/infrastructure/primary/ReactI18nModuleConfiguration.java index 4b245b4f8f5..18eafdb0af3 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/react/i18n/infrastructure/primary/ReactI18nModuleConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/client/react/i18n/infrastructure/primary/ReactI18nModuleConfiguration.java @@ -15,7 +15,7 @@ class ReactI18nModuleConfiguration { @Bean - JHipsterModuleResource i18nModule(ReactI18nApplicationService i18n) { + JHipsterModuleResource reactI18nModule(ReactI18nApplicationService i18n) { return JHipsterModuleResource.builder() .slug(REACT_I18N) .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().build()) diff --git a/src/main/java/tech/jhipster/lite/generator/client/vue/i18n/application/VueI18nApplicationService.java b/src/main/java/tech/jhipster/lite/generator/client/vue/i18n/application/VueI18nApplicationService.java new file mode 100644 index 00000000000..f669a15ac20 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/client/vue/i18n/application/VueI18nApplicationService.java @@ -0,0 +1,20 @@ +package tech.jhipster.lite.generator.client.vue.i18n.application; + +import org.springframework.stereotype.Service; +import tech.jhipster.lite.generator.client.vue.i18n.domain.VueI18nModuleFactory; +import tech.jhipster.lite.module.domain.JHipsterModule; +import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; + +@Service +public class VueI18nApplicationService { + + private final VueI18nModuleFactory factory; + + public VueI18nApplicationService() { + factory = new VueI18nModuleFactory(); + } + + public JHipsterModule buildModule(JHipsterModuleProperties properties) { + return factory.buildModule(properties); + } +} diff --git a/src/main/java/tech/jhipster/lite/generator/client/vue/i18n/domain/VueI18nModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/client/vue/i18n/domain/VueI18nModuleFactory.java new file mode 100644 index 00000000000..005f1da2428 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/client/vue/i18n/domain/VueI18nModuleFactory.java @@ -0,0 +1,75 @@ +package tech.jhipster.lite.generator.client.vue.i18n.domain; + +import static tech.jhipster.lite.module.domain.JHipsterModule.*; + +import tech.jhipster.lite.module.domain.JHipsterModule; +import tech.jhipster.lite.module.domain.file.JHipsterSource; +import tech.jhipster.lite.module.domain.packagejson.VersionSource; +import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; +import tech.jhipster.lite.shared.error.domain.Assert; + +public class VueI18nModuleFactory { + + private static final JHipsterSource APP_SOURCE = from("client/vue/i18n/src/main/webapp/app"); + private static final JHipsterSource ASSETS_FR_SOURCE = from("client/common/i18n/locales/fr"); + private static final JHipsterSource ASSETS_EN_SOURCE = from("client/common/i18n/locales/en"); + private static final JHipsterSource TEST_SOURCE = from("client/vue/i18n/src/test"); + + private static final String INDEX = "src/main/webapp/"; + private static final String INDEX_TEST = "src/test/"; + + public JHipsterModule buildModule(JHipsterModuleProperties properties) { + Assert.notNull("properties", properties); + + //@formatter:off + return moduleBuilder(properties) + .packageJson() + .addDependency(packageName("i18next"), VersionSource.COMMON) + .addDependency(packageName("i18next-vue"), VersionSource.VUE) + .addDependency(packageName("i18next-browser-languagedetector"), VersionSource.COMMON) + .and() + .files() + .batch(APP_SOURCE, to(INDEX + "/app")) + .addFile("i18n.ts") + .and() + .batch(ASSETS_EN_SOURCE, to(INDEX + "content/locales/en/")) + .addFile("common.json") + .addFile("homepage.json") + .and() + .batch(ASSETS_FR_SOURCE, to(INDEX + "content/locales/fr/")) + .addFile("common.json") + .addFile("homepage.json") + .and() + .batch(TEST_SOURCE, to(INDEX_TEST)) + .addFile("setupTests.ts") + .and() + .and() + .mandatoryReplacements() + .in(path(INDEX + "app/main.ts")) + .add(lineBeforeText("// jhipster-needle-main-ts-import"), "import i18next from './i18n';") + .add(lineBeforeText("// jhipster-needle-main-ts-import"), "import I18NextVue from 'i18next-vue';") + .add(lineBeforeText("app.mount('#app');"), "app.use(I18NextVue, { i18next });") + .and() + .in(path(INDEX + "app/common/primary/homepage/Homepage.html")) + .add(lineAfterRegex("Vue 3 \\+ TypeScript \\+ Vite"), properties.indentation().times(1) + "
") + .add(lineAfterRegex("Vue 3 \\+ TypeScript \\+ Vite"), properties.indentation().times(1) + "") + .and() + .in(path("./vitest.config.ts")) + .add(lineAfterRegex("test:"), properties.indentation().times(2) + "setupFiles: ['./src/test/setupTests.ts'],") + .and() + .in(path(INDEX_TEST + "webapp/unit/common/primary/homepage/Homepage.spec.ts")) + .add(append(), LINE_BREAK + """ + describe('App I18next', () => { + it('should renders with translation', () => { + wrap(); + + expect(wrapper.text()).toContain("translationEnabled"); + }); + }); + """) + .and() + .and() + .build(); + //@formatter:off + } +} diff --git a/src/main/java/tech/jhipster/lite/generator/client/vue/i18n/infrastructure/primary/VueI18nModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/client/vue/i18n/infrastructure/primary/VueI18nModuleConfiguration.java new file mode 100644 index 00000000000..6f9614c7fab --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/client/vue/i18n/infrastructure/primary/VueI18nModuleConfiguration.java @@ -0,0 +1,27 @@ +package tech.jhipster.lite.generator.client.vue.i18n.infrastructure.primary; + +import static tech.jhipster.lite.generator.slug.domain.JHLiteFeatureSlug.CLIENT_INTERNATIONALIZATION; +import static tech.jhipster.lite.generator.slug.domain.JHLiteModuleSlug.VUE_CORE; +import static tech.jhipster.lite.generator.slug.domain.JHLiteModuleSlug.VUE_I18N; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import tech.jhipster.lite.generator.client.vue.i18n.application.VueI18nApplicationService; +import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization; +import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition; +import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource; + +@Configuration +class VueI18nModuleConfiguration { + + @Bean + JHipsterModuleResource vueI18nModule(VueI18nApplicationService i18n) { + return JHipsterModuleResource.builder() + .slug(VUE_I18N) + .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().build()) + .apiDoc("Frontend - Vue", "Add vue internationalization") + .organization(JHipsterModuleOrganization.builder().feature(CLIENT_INTERNATIONALIZATION).addDependency(VUE_CORE).build()) + .tags("client", "vue", "i18n") + .factory(i18n::buildModule); + } +} diff --git a/src/main/java/tech/jhipster/lite/generator/client/vue/i18n/package-info.java b/src/main/java/tech/jhipster/lite/generator/client/vue/i18n/package-info.java new file mode 100644 index 00000000000..4cc0fb5bcad --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/client/vue/i18n/package-info.java @@ -0,0 +1,2 @@ +@tech.jhipster.lite.BusinessContext +package tech.jhipster.lite.generator.client.vue.i18n; diff --git a/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java b/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java index b33ecd337ac..ffef5b2008f 100644 --- a/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java +++ b/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java @@ -146,6 +146,7 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory { SVELTE_CORE("svelte-core"), TYPESCRIPT("typescript"), VUE_CORE("vue-core"), + VUE_I18N("vue-i18next"), VUE_PINIA("vue-pinia"), TS_PAGINATION_DOMAIN("ts-pagination-domain"), TS_REST_PAGINATION("ts-rest-pagination"); diff --git a/src/main/resources/generator/client/common/i18n/locales/en/common.json b/src/main/resources/generator/client/common/i18n/locales/en/common.json new file mode 100644 index 00000000000..c1852ea0f25 --- /dev/null +++ b/src/main/resources/generator/client/common/i18n/locales/en/common.json @@ -0,0 +1,3 @@ +{ + "translationEnabled": "Internationalisation enabled namespace common" +} diff --git a/src/main/resources/generator/client/common/i18n/locales/en/homepage.json b/src/main/resources/generator/client/common/i18n/locales/en/homepage.json new file mode 100644 index 00000000000..bb41a2c628a --- /dev/null +++ b/src/main/resources/generator/client/common/i18n/locales/en/homepage.json @@ -0,0 +1,3 @@ +{ + "translationEnabled": "Internationalization enabled namespace Homepage" +} diff --git a/src/main/resources/generator/client/common/i18n/locales/fr/common.json b/src/main/resources/generator/client/common/i18n/locales/fr/common.json new file mode 100644 index 00000000000..0ac486d8389 --- /dev/null +++ b/src/main/resources/generator/client/common/i18n/locales/fr/common.json @@ -0,0 +1,3 @@ +{ + "translationEnabled": "Internationalisation activée namespace common" +} diff --git a/src/main/resources/generator/client/common/i18n/locales/fr/homepage.json b/src/main/resources/generator/client/common/i18n/locales/fr/homepage.json new file mode 100644 index 00000000000..5542f2be86a --- /dev/null +++ b/src/main/resources/generator/client/common/i18n/locales/fr/homepage.json @@ -0,0 +1,3 @@ +{ + "translationEnabled": "Internationalisation activée namespace homepage" +} diff --git a/src/main/resources/generator/client/vue/i18n/src/main/webapp/app/i18n.ts b/src/main/resources/generator/client/vue/i18n/src/main/webapp/app/i18n.ts new file mode 100644 index 00000000000..6208b7428cd --- /dev/null +++ b/src/main/resources/generator/client/vue/i18n/src/main/webapp/app/i18n.ts @@ -0,0 +1,45 @@ +import i18n, { type ResourceLanguage } from 'i18next'; +import LanguageDetector from 'i18next-browser-languagedetector'; + +const sources: Record+ Recommended IDE setup: + VSCode + + + Volar +
+ ++ Vite Documentation + | + Vue 3 Documentation +
+ +
+ Edit
+ src/main/webapp/app/common/primary/app/AppVue.vue
to test hot module replacement.
+