Skip to content

Latest commit

 

History

History
38 lines (25 loc) · 1.13 KB

i18n.md

File metadata and controls

38 lines (25 loc) · 1.13 KB

#i18n (Internationalization)

There is i18n for everything a guest can see and visit. We have not need to do any i18n for the Enonics backend admin or content studio.

To make i18n possible we use the properties files in /src/main/resources/site/i8n.

  • phrases.properties : norwegian (default)
  • phrases_en.properties : english

In each of the controllers, be it page, layout or part, we use the method getLanguage to see which language the guests use. Then get the proper phrases and send them to the frontend in thymeleaf or react. We should not use any i18n functions in frontend code.

See enonic i18n docs for more information about how to use i18n functions in the controllers.

Use localize to get the right phrases.

import { localize } from '/lib/xp/i18n'
import { getLanguage } from '/lib/language'

export function get(req: XP.Request) {
    const currentLanguage = getLanguage(req)    

    const searchPlaceholder = localize({
        key: 'menuDropdown.search',
        locale: currentLanguage.code,
    });

}