Japanese 日本語

BCP 47 language tag: ja

Lokalized supports cardinality, cardinality range, and ordinality rules for Japanese.

Additional modeled concepts for Japanese: classifiers and counters; formality and register, including humble and honorific variants.

Japanese is most often spoken in Japan, Brazil, and Canada.

Cardinalities

All numbers use CARDINALITY_OTHER; no value selects a different form.

Example: 2 日.

Cardinality Ranges

Every range resolves to CARDINALITY_OTHER because every endpoint is CARDINALITY_OTHER, so no range can select a different form.

Ordinalities

All ordinal numbers use ORDINALITY_OTHER; no value selects a different form.

Example: 2 番目の角を右折します。.

Language-Specific Examples

These examples show how Lokalized models grammatical choices and translation behavior that commonly affect Japanese application copy. Each example identifies the Lokalized language forms and other library features it uses.

Counters by classifier

Japanese uses different counters for different semantic classes, such as bound volumes and machines.

Language references: Japan Foundation - counters by an object's shape or properties, Japan Foundation - counter grammar and examples

Language forms used: classifier

Sample localized strings file
ja.json Localized Strings File (Japanese)
{
  "I bought {{count}} items.": {
    "translation": "{{count}}{{counter}}買いました。",
    "placeholders": {
      "counter": {
        "value": "classifier",
        "translations": {
          "CLASSIFIER_GENERAL": "つ",
          "CLASSIFIER_BOUND": "冊",
          "CLASSIFIER_MACHINE": "台"
        }
      }
    }
  }
}
Usage and expected results

JavaScript

import { CLASSIFIER_BOUND, CLASSIFIER_GENERAL, CLASSIFIER_MACHINE, createStrings } from "lokalized";
import { readStringsFromDirectory } from "lokalized/node";

const locale = "ja";

const strings = createStrings({
  localizedStringSupplier: () => readStringsFromDirectory("strings").catalogs,
  fallbackLocale: locale,
  localeSupplier: () => locale,
});

strings.get("I bought {{count}} items.", {
  count: 4,
  classifier: CLASSIFIER_GENERAL,
});   // => "4つ買いました。"
strings.get("I bought {{count}} items.", { count: 3, classifier: CLASSIFIER_BOUND });   // => "3冊買いました。"
strings.get("I bought {{count}} items.", {
  count: 2,
  classifier: CLASSIFIER_MACHINE,
});   // => "2台買いました。"

Java

Locale locale = Locale.forLanguageTag("ja");

Strings strings = Strings.withFallbackLocale(locale)
  .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings")))
  .localeSupplier((matcher) -> matcher.bestMatchFor(locale))
  .build();

assertEquals("4つ買いました。", strings.get(
  "I bought {{count}} items.", Map.of("count", 4, "classifier", Classifier.GENERAL)
));

assertEquals("3冊買いました。", strings.get(
  "I bought {{count}} items.", Map.of("count", 3, "classifier", Classifier.BOUND)
));

assertEquals("2台買いました。", strings.get(
  "I bought {{count}} items.", Map.of("count", 2, "classifier", Classifier.MACHINE)
));

Swift

Swift uses pinned CLDR rules for raw numeric values. The display strings in these assertions are fixed examples; applications format display values separately with Foundation. Default .rtlLocales bidi isolation adds FSI/PDI to interpolated values in right-to-left output.

import Foundation
import Lokalized

let locale = try LocaleTag("ja")
let files = try LocalizedStringLoader.loadFromDirectory(URL(fileURLWithPath: "strings"))
let catalogs = files.mapValues { LocalizedCatalog(strings: $0.strings) }

let strings = try DefaultStrings(configuration: StringsConfiguration(
  localizedStringSupplier: { catalogs }, localeSupplier: { _ in locale },
  fallbackLocale: locale
))

let message1 = try strings.get("I bought {{count}} items.", placeholders: [
  "count": .number(try NumericValue.forDecimal("4")),
  "classifier": .languageForm(.classifier(.general)),
])
assert(ExactString(message1) == ExactString("4つ買いました。"))

let message2 = try strings.get("I bought {{count}} items.", placeholders: [
  "count": .number(try NumericValue.forDecimal("3")),
  "classifier": .languageForm(.classifier(.bound)),
])
assert(ExactString(message2) == ExactString("3冊買いました。"))

let message3 = try strings.get("I bought {{count}} items.", placeholders: [
  "count": .number(try NumericValue.forDecimal("2")),
  "classifier": .languageForm(.classifier(.machine)),
])
assert(ExactString(message3) == ExactString("2台買いました。"))

Welcome phrases by interaction context

These welcome phrases are context-specific, not four interchangeable politeness grades: いらっしゃい can greet a familiar visitor, ようこそ welcomes someone to a place, service staff use いらっしゃいませ, and お待ちしておりました presupposes an expected arrival. Treat the mapping as a product-context example and have its exact use reviewed by a native speaker.

Language references: NINJAL - role-bound use of いらっしゃいませ, Japan Tourism Agency - ようこそ and いらっしゃいませ, Agency for Cultural Affairs - honorific and humble Japanese, Gakushuin University - いらっしゃい as a home greeting

Language forms used: formality

Sample localized strings file
ja.json Localized Strings File (Japanese)
{
  "Welcome.": {
    "translation": "{{welcome}}",
    "placeholders": {
      "welcome": {
        "value": "formality",
        "translations": {
          "FORMALITY_CASUAL": "いらっしゃい。",
          "FORMALITY_FORMAL": "ようこそ。",
          "FORMALITY_HONORIFIC": "いらっしゃいませ。",
          "FORMALITY_HUMBLE": "お待ちしておりました。"
        }
      }
    }
  }
}
Usage and expected results

JavaScript

import { FORMALITY_CASUAL, FORMALITY_FORMAL, FORMALITY_HONORIFIC, FORMALITY_HUMBLE, createStrings } from "lokalized";
import { readStringsFromDirectory } from "lokalized/node";

const locale = "ja";

const strings = createStrings({
  localizedStringSupplier: () => readStringsFromDirectory("strings").catalogs,
  fallbackLocale: locale,
  localeSupplier: () => locale,
});

strings.get("Welcome.", { formality: FORMALITY_CASUAL });   // => "いらっしゃい。"
strings.get("Welcome.", { formality: FORMALITY_FORMAL });   // => "ようこそ。"
strings.get("Welcome.", { formality: FORMALITY_HONORIFIC });   // => "いらっしゃいませ。"
strings.get("Welcome.", { formality: FORMALITY_HUMBLE });   // => "お待ちしておりました。"

Java

Locale locale = Locale.forLanguageTag("ja");

Strings strings = Strings.withFallbackLocale(locale)
  .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings")))
  .localeSupplier((matcher) -> matcher.bestMatchFor(locale))
  .build();

assertEquals("いらっしゃい。", strings.get(
  "Welcome.", Map.of("formality", Formality.CASUAL)
));

assertEquals("ようこそ。", strings.get(
  "Welcome.", Map.of("formality", Formality.FORMAL)
));

assertEquals("いらっしゃいませ。", strings.get(
  "Welcome.", Map.of("formality", Formality.HONORIFIC)
));

assertEquals("お待ちしておりました。", strings.get(
  "Welcome.", Map.of("formality", Formality.HUMBLE)
));

Swift

Swift uses pinned CLDR rules for raw numeric values. The display strings in these assertions are fixed examples; applications format display values separately with Foundation. Default .rtlLocales bidi isolation adds FSI/PDI to interpolated values in right-to-left output.

import Foundation
import Lokalized

let locale = try LocaleTag("ja")
let files = try LocalizedStringLoader.loadFromDirectory(URL(fileURLWithPath: "strings"))
let catalogs = files.mapValues { LocalizedCatalog(strings: $0.strings) }

let strings = try DefaultStrings(configuration: StringsConfiguration(
  localizedStringSupplier: { catalogs }, localeSupplier: { _ in locale },
  fallbackLocale: locale
))

let message1 = try strings.get("Welcome.", placeholders: [
  "formality": .languageForm(.formality(.casual)),
])
assert(ExactString(message1) == ExactString("いらっしゃい。"))

let message2 = try strings.get("Welcome.", placeholders: [
  "formality": .languageForm(.formality(.formal)),
])
assert(ExactString(message2) == ExactString("ようこそ。"))

let message3 = try strings.get("Welcome.", placeholders: [
  "formality": .languageForm(.formality(.honorific)),
])
assert(ExactString(message3) == ExactString("いらっしゃいませ。"))

let message4 = try strings.get("Welcome.", placeholders: [
  "formality": .languageForm(.formality(.humble)),
])
assert(ExactString(message4) == ExactString("お待ちしておりました。"))

Addendum: Language Form Rules

The language form expressions above are specified by Unicode Technical Standard #35 and use the following notation:

  • n absolute value of the source number (integer and decimals)
  • i integer digits of n
  • v number of visible fraction digits in n, with trailing zeros
  • w number of visible fraction digits in n, without trailing zeros
  • f visible fractional digits in n, with trailing zeros
  • t visible fractional digits in n, without trailing zeros
  • c/e compact decimal exponent operands used by some CLDR compact-number rules