Lingo.dev + .properties (Java)

Lingo.dev CLIはJavaの.propertiesファイルを翻訳する際に、キーと値の構造、エスケープシーケンス、およびJavaのローカリゼーション規則を保持します。CLIはJavaのResourceBundleシステムとシームレスに連携し、propertiesファイルの形式を正確に維持し、UnicodeおよびJavaの特殊文字のエスケープを正しく処理し、MessageFormat用の{0}{1}プレースホルダーを保持し、MavenおよびGradleビルドプロセスと統合します。

クイックセットアップ

Javaのpropertiesファイル用の設定:

{
  "locale": {
    "source": "en",
    "targets": ["es", "fr", "de"]
  },
  "buckets": {
    "properties": {
      "include": ["src/main/resources/messages_[locale].properties"]
    }
  }
}

注意: [locale]は設定内でそのまま残しておくべきプレースホルダーであり、CLI実行時に実際のロケールに置き換えられます。

propertiesファイルの翻訳

npx lingo.dev@latest i18n

値を翻訳する際に、propertiesファイルの形式、エスケープシーケンス、およびJava固有の規則を保持します。

propertiesファイルの構造

基本的なキーと値のペア

welcome.message=Welcome to our application
login.button=Log In
logout.button=Log Out
error.invalid.credentials=Invalid username or password

名前空間の構成


# 認証メッセージ

auth.login.title=Sign In
auth.login.subtitle=Enter your credentials
auth.register.title=Create Account
auth.forgot.password=Forgot Password?

# ナビゲーション項目

nav.home=Home
nav.dashboard=Dashboard
nav.settings=Settings

MessageFormatプレースホルダー

welcome.user=Welcome back, {0}!
items.count=You have {0} items in your cart
validation.min.length=Field must be at least {0} characters long
date.format=Today is {0,date,short}

Java固有の機能

Unicodeエスケープシーケンス

japanese.greeting=\u3053\u3093\u306b\u3061\u306f
euro.symbol=Price: 100\u20ac

Unicodeエスケープは翻訳中も保持されます。

行の継続

long.message=This is a very long message that \
    spans multiple lines for better \
    readability in the source file

特殊文字のエスケープ

file.path=C:\\Users\\Documents\\file.txt
key.with.spaces=key\ with\ spaces=value with spaces
special.chars=Contains \= equals and \: colons

高度な設定

複数のプロパティファイル

"properties": {
  "include": [
    "src/main/resources/messages_[locale].properties",
    "src/main/resources/validation_[locale].properties"
  ]
}

設定キーのロック

"properties": {
  "include": ["src/main/resources/messages_[locale].properties"],
  "lockedKeys": ["app.version", "build.timestamp", "api.endpoint"]
}