Discourse 테마 또는 테마 컴포넌트에 사용자 정의 언어와 번역을 추가하려는 경우, 이제 UI 컴포넌트에서 사용할 수 있는 로컬라이즈드 문자열을 포함할 수 있습니다. 번역은 코어/플러그인 번역과 동일한 형식으로 저장되며, 거의 동일한 방식으로 사용할 수 있습니다.
테마는 /locales/{locale}.yml과 같은 형식으로 번역 파일을 제공할 수 있습니다. 이러한 파일은 정의되는 로케일과 동일한 단일 최상위 키를 가진 유효한 YAML이어야 합니다. discourse_theme CLI, .tar.gz 가져오기, GIT 저장소에서 설치하거나 theme-creator.discourse.org의 편집기를 통해 정의할 수 있습니다.
로케일 파일의 예시는 다음과 같습니다.
en:
theme_metadata:
description: "This is a description for my theme"
settings:
theme_setting_name: "This is a description for the setting `theme_setting_name`"
another_theme_setting_name:
description: "This is a description for the setting `another_theme_setting_name`"
sidebar:
welcome: "Welcome"
back: "back,"
welcome_subhead: "We're glad you're here!"
likes_header: "Share the Love"
badges_header: "Your Top Badges"
full_profile: "View your full profile"
관리자는 /admin/customize/themes 사용자 인터페이스에서 테마별로 개별 키를 오버라이드할 수 있습니다. 폴백은 코어와 동일한 방식으로 처리되므로, 영어 이외의 언어에 불완전한 번역이 있어도 영어 키가 사용됩니다.
관리자는 또한 Appearance → Site texts에서 이러한 번역을 관리할 수 있습니다. 테마 또는 컴포넌트를 선택하여 해당 로케일 파일 문자열을 검색하고, 선택된 언어로 번역을 편집하거나, 오버라이드를 로케일 파일 기본값으로 되돌릴 수 있습니다. 선택 항목은 /admin/customize/site_texts?theme_id=THEME_ID를 사용하여 링크할 수 있습니다. Site texts는 이러한 항목을 js.theme_translations.THEME_ID.KEY로 식별하며, 편집은 테마 편집기와 동일한 테마 번역 오버라이드를 사용합니다.
백그라운드에서 이러한 번역은 코어 번역과 함께 테마별 네임스페이스 아래에 저장됩니다. 예를 들어:
theme_translation.{theme_id}.sidebar.welcome
테마 코드에서 theme_id를 하드코딩해서는 안 됩니다. 번역 키를 동적으로 구성하려면 themePrefix 헬퍼를 사용하세요:
import { i18n } from "discourse-i18n";
import { themePrefix } from "virtual:theme";
// In JS code:
const result = i18n(themePrefix("my_translation_key"));
console.log("From Javascript", result);
// In a template tag:
<template>{{i18n (themePrefix "blah")}}</template>
테마에서 번역을 사용하는 완전한 예시는 @awesomerobot의 Fakebook 테마를 확인하세요: GitHub - discourse/Fakebook · GitHub
이 문서는 버전 관리됩니다 - 변경 사항을 github에서 제안하세요.


