l10n_countries 1.0.0
l10n_countries: ^1.0.0 copied to clipboard
Provides country names translations (for 194 different locales).
This ISO-driven, pure Dart, fully tested and dependency-free package provides translations for country names in 194
different locales. For Flutter ready widgets (like country picker) please use world_countries package. For Dart-only use - it's recommended to use together with sealed_countries package.
Features #
- 194 locales supported out of the box.
- Three-letter ISO 3166-1 Alpha-3 code lookup.
- Fallback locale support.
- Alternative names support.
Getting started #
To use this package, add l10n_countries
as a dependency in your pubspec.yaml
file.
dependencies:
l10n_countries: any
Then import the package in your Dart code:
import 'package:l10n_countries/l10n_countries.dart';
Usage #
Use the CountriesLocaleMapper
class to localize country names. Create an instance and use the localize method to get translations:
void main() {
/// Create an instance of the mapper directly.
final mapper = CountriesLocaleMapper();
/// Define some ISO codes to localize (e.g., `USA` for United States,
/// `RUS` for Russian Federation, and `POL` for Poland).
final isoCodes = {"USA", "RUS", "POL"};
/// Localize the codes with an optional main locale (e.g., "sk" for Slovak),
/// and an optional fallback locale (e.g., "cs" for Czech).
final localized =
mapper.localize(isoCodes, mainLocale: "sk", fallbackLocale: "cs");
print("Names count: ${localized.length}"); // Prints: "Names count: 12".
/// Print out the localized names.
localized.forEach(
(country, l10n) => print(
'Localized name of country with ISO code "${country.isoCode}" '
'for locale "${country.locale}" is "$l10n"',
),
);
}
FAQ #
Why should I use this package over any other country-related package?
- No dependencies: This package has no dependencies, ensuring that you won't have any issues or conflicts with other dependencies (no even
meta
here, because of that). - Rich data: This package offers tons of translations (all GlobalMaterialLocalizations and GlobalCupertinoLocalizations locales and more).
- High code coverage: The code in this package has 100% code coverage, providing confidence in its reliability and stability.
- Comprehensive documentation: This package provides full documentation for every non-code generated public member, usually with examples, ensuring clarity and ease of use.
- Industry adopted: This package is actively used in production by numerous European companies, ensuring its efficacy and robustness in real-world scenarios.
- Lightweight: This package keeps under 500 KB, ensuring it fits within the pub cache limit. This leads to quick, low-bandwidth downloads and faster caching, minimizing resource impact.
- MIT license: This package and sources are released under the MIT license, which is a permissive license that allows users to use, modify, and distribute the code with minimal restrictions. The MIT license is considered better than most other open-source licenses because it provides flexibility and allows users to incorporate the code into their projects without worrying about legal implications.
Additional information #
If you like this package, please give it a star or like. For more information on using this package, check out the API documentation. PRs or ideas are always welcome. If you have any issues or suggestions for the package, please file them in the GitHub repository.