Skip to main content

is_zh 1.0.0 copy "is_zh: ^1.0.0" to clipboard
is_zh: ^1.0.0 copied to clipboard

Detect Chinese, simplified Chinese, and traditional Chinese locales from a Flutter BuildContext.

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.

0
likes
150
points
68
downloads

Documentation

API reference

Publisher

verified publisherflutter-cavalry.com

Weekly Downloads

Detect Chinese, simplified Chinese, and traditional Chinese locales from a Flutter BuildContext.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on is_zh