Simplified Chinese 简体中文

BCP 47 language tag: zh-Hans

Lokalized supports cardinality, cardinality range, and ordinality rules for Simplified Chinese.

Additional modeled concepts for Simplified Chinese: classifiers and counters.

Simplified Chinese is most often spoken in China, Malaysia, Singapore, Canada, and Hong Kong SAR China.

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 Simplified Chinese application copy. Each example identifies the Lokalized language forms and other library features it uses.

Classifier and noun phrases

Passing CLASSIFIER_GENERAL, CLASSIFIER_BOUND, or CLASSIFIER_MACHINE selects the complete classifier-and-noun phrase that follows the application-supplied count: 个苹果 for apples, 本书 for books, or 台电脑 for computers.

Language references: Ohio State University - Plurals and classifiers in Chinese, National Taiwan Normal University Mandarin Training Center - 台 for machines and appliances

Language forms used: classifier

Sample localized strings file
zh-Hans.json Localized Strings File (Simplified Chinese)
{
  "I bought {{count}} items.": {
    "translation": "我买了{{count}}{{item}}。",
    "placeholders": {
      "item": {
        "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 = "zh-Hans";

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

strings.get("I bought {{count}} items.", {
  count: 3,
  classifier: CLASSIFIER_GENERAL,
});   // => "我买了3个苹果。"
strings.get("I bought {{count}} items.", { count: 2, classifier: CLASSIFIER_BOUND });   // => "我买了2本书。"
strings.get("I bought {{count}} items.", {
  count: 1,
  classifier: CLASSIFIER_MACHINE,
});   // => "我买了1台电脑。"

Java

Locale locale = Locale.forLanguageTag("zh-Hans");

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

assertEquals("我买了3个苹果。", strings.get(
  "I bought {{count}} items.", Map.of("count", 3, "classifier", Classifier.GENERAL)
));

assertEquals("我买了2本书。", strings.get(
  "I bought {{count}} items.", Map.of("count", 2, "classifier", Classifier.BOUND)
));

assertEquals("我买了1台电脑。", strings.get(
  "I bought {{count}} items.", Map.of("count", 1, "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("zh-Hans")
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("3")),
  "classifier": .languageForm(.classifier(.general)),
])
assert(ExactString(message1) == ExactString("我买了3个苹果。"))

let message2 = try strings.get("I bought {{count}} items.", placeholders: [
  "count": .number(try NumericValue.forDecimal("2")),
  "classifier": .languageForm(.classifier(.bound)),
])
assert(ExactString(message2) == ExactString("我买了2本书。"))

let message3 = try strings.get("I bought {{count}} items.", placeholders: [
  "count": .number(try NumericValue.forDecimal("1")),
  "classifier": .languageForm(.classifier(.machine)),
])
assert(ExactString(message3) == ExactString("我买了1台电脑。"))

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