is_zh

pub package

Detect Chinese locales from a Flutter BuildContext.

Getting started

Add the package to your Flutter project:

flutter pub add is_zh

Usage

import 'package:is_zh/is_zh.dart';

// Use a context below MaterialApp, CupertinoApp, or Localizations.
final chinese = isZh(context);
final simplified = isZhSimplified(context);
final traditional = isZhTraditional(context);

All three functions read Localizations.localeOf(context) and rebuild their calling widget when the locale changes.

  • isZh: true when the language code is zh.
  • isZhSimplified: true for Chinese with script Hans, or region CN/SG/MY when no script is specified.
  • isZhTraditional: true for Chinese with script Hant, or region TW/HK/MO when no script is specified.

An explicit script takes precedence over the region. Other explicit scripts match neither variant. Chinese locales with no script and no recognized region (including bare zh) match neither variant, but still match isZh.

A context without a Localizations ancestor is invalid.

Libraries

is_zh