国际化 Internationalization

介绍 Introduction

在创建一个新项目期间,您将被问及是否要启用国际化支持。

如果启用它,您将需要选择应用程序的母语。之后,您可以选择要安装的其他语言。如果您不想从开始支持任何其他语言,您可以随时通过运行语言子生成器添加语言。

如果您确定不会将此应用程序翻译成另一种语言,则不应启用国际化。

支持的语言

These are the currently supported languages

  • Armenian
  • Catalan
  • Chinese (Simplified)
  • Chinese (Traditional)
  • Danish
  • English
  • French
  • Galician
  • German
  • Greek
  • Hindi
  • Italian
  • Japanese
  • Hindi
  • Hungarian
  • Korean
  • Marathi
  • Netherlands
  • Polish
  • Portuguese
  • Portuguese (Brazilian)
  • Russian
  • Romanian
  • Serbian
  • Spanish
  • Swedish
  • Tamil
  • Thai
  • Turkish
  • Ukrainian
  • Vietnamese

Your language is missing in JHipster? Help us improve the project with a PR!

项目生成后如何添加语言? How to add languages after project generation?

为此,您可以使用以下语言运行语言子生成器:

jhipster languages

请注意,如果您希望使用刚添加的语言翻译实体,则需要重新生成实体。

如何添加不支持的新语言? How to add a new language that is not supported?

所有语言都保存在文件夹 src/main/webapp/i18n (客户端)和 src/main/resources/i18n (服务器端)

以下是安装新语言的步骤 new_lang:

  1. 复制 src/main/webapp/i18/en folder to src/main/webapp/i18/new_lang (这是存储所有前端翻译的地方)
  2. Translate all files under the folder src/main/webapp/i18/new_lang
  3. 对于AngularJS 1,将语言代码添加 new_langLANGUAGES 定义的常量中src/main/webapp/app/components/language/language.constants.js

    .constant('LANGUAGES', [
        'en',
        'fr',
        'new_lang'
        // jhipster-needle-i18n-language-constant - JHipster will add/remove languages in this array
    ]
    

    对于Angular 2+,add the language code new_lang to the LANGUAGES constant defined in src/main/webapp/app/shared/language/language.constants.ts

    export const LANGUAGES: string[] = [
        'en',
        'fr',
        'new_lang'
        // jhipster-needle-i18n-language-constant - JHipster will add/remove languages in this array
    ];
    
  4. In the src/main/resources/i18n folder, copy the messages_en.properties file to messages_new_lang.properties (这是存储服务器端翻译的地方)

  5. Translate all keys in the messages_new_lang.properties file
  6. For AngularJS 1 add the new language's name in the function of filter('findLanguageFromKey') in the src/main/webapp/app/components/language/language.filter.js file. For Angular 2+ add the new language's name in the languages variable of FindLanguageFromKeyPipe in the src/main/webapp/app/shared/language/language.pipe.ts
  7. 对于Angular 2+,添加新的语言捆绑 webpack.common.js

     new MergeJsonWebpackPlugin({
         output: {
             groupBy: [
                 { pattern: "./src/main/webapp/i18n/en/*.json", fileName: "./i18n/en.json" },
                 { pattern: "./src/main/webapp/i18n/new_lang/*.json", fileName: "./i18n/new_lang.json" }
                 // jhipster-needle-i18n-language-webpack - JHipster will add/remove languages in this array
             ]
         }
     })
    

新语言 new_lang 现在可以在语言菜单中使用,它可以在前端Angular应用程序和后端Spring应用程序中使用。

如何删除现有语言? How to remove an existing language?

Here are the steps to remove a language called old_lang:

  1. Remove the language folder from src/main/webapp/i18/old_lang
  2. Remove the constant entry in src/main/webapp/app/components/language/language.constants.js or src/main/webapp/app/shared/language/language.constants.ts
  3. Remove the src/main/resources/i18n/messages_old_lang.properties file

results matching ""

    No results matching ""