Skip to content

Commit

Permalink
Implement support for TimeZone information + General enhancements (#14)
Browse files Browse the repository at this point in the history
Add support for Timezones
Included all locales that are available from CLDR
Changed includes to improve compile times when only limited number of locales is used (breaking change)
Improved documentation
Update to CLDR 46
  • Loading branch information
arjanmels authored Nov 21, 2024
1 parent 4f37bd3 commit 9a150fb
Show file tree
Hide file tree
Showing 5,614 changed files with 7,494,725 additions and 36,635 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ doc/api/
_*
.*

pubspec.lock

!.gitignore
!.github
!.pubignore

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 1.2.0

- Added timezone data
- Improved documentation
- General code improvements
- Removed ```cld``` global variable
- More flexible locale inclusion during generation
- Improved compile time by not by default importing/exporting all locales
- Add all locales available in CLDR

## 1.1.0

- Update to latest data of CLDR
Expand Down
46 changes: 46 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2022 xaha
Copyright (c) 2024 Arjan Mels

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,3 +20,48 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



The Unicode CLDR data used in this software is licensed under the following terms

##UNICODE_LICENSE##
UNICODE LICENSE V3

COPYRIGHT AND PERMISSION NOTICE

Copyright © 1991-2024 Unicode, Inc.

NOTICE TO USER: Carefully read the following legal agreement. BY
DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.

Permission is hereby granted, free of charge, to any person obtaining a
copy of data files and any associated documentation (the "Data Files") or
software and any associated documentation (the "Software") to deal in the
Data Files or Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, and/or sell
copies of the Data Files or Software, and to permit persons to whom the
Data Files or Software are furnished to do so, provided that either (a)
this copyright and permission notice appear with all copies of the Data
Files or Software, or (b) this copyright and permission notice appear in
associated Documentation.

THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
THIRD PARTY RIGHTS.

IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
FILES OR SOFTWARE.

Except as contained in this notice, the name of a copyright holder shall
not be used in advertising or otherwise to promote the sale, use or other
dealings in these Data Files or Software without prior written
authorization of the copyright holder.
504 changes: 485 additions & 19 deletions README.md

Large diffs are not rendered by default.

42 changes: 33 additions & 9 deletions README.template.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

# common_locale_data

This packages provides a type-safe and tree-shakable way to access translated common data.
The translations are extracted from the Common Locale Data Repository ([CLDR](https://cldr.unicode.org/)).
The translations are extracted from the Common Locale Data
Repository ([CLDR](https://cldr.unicode.org/)).

## Available data
- Translations for measurement units in full and abbreviated forms including singular/plural modifications.

- Translations for measurement units in full and abbreviated forms including singular/plural
modifications.
- Translations for language names.
- Translations for territory and country names.
- Translations for currency names, including singular/plural modifications.
Expand All @@ -16,21 +18,43 @@ The translations are extracted from the Common Locale Data Repository ([CLDR](ht

## Tree-shaking

All the data and translations are stored as literal strings in the code. The APIs are designed to be
tree-shakeable. The final application's binaries won't include the translations for languages you don't use.
All the data and translations are stored as literal strings in the code. The APIs are designed to be
tree-shakeable. The final application's binaries won't include the translations for languages you
don't use.

## Compilation

To improve compilation speed locales need to be imported individually when
using [common_locale_data].
For example for English: ```import 'package:common_locale_data/en.dart';``` or for
French: ```import 'package:common_locale_data/fr.dart';```

You can import all locales via [common_locale_data_all]. However this will increase compilation time
significantly (10x over including just a couple of locales). As long as you don't use
the [CommonLocaleDataAll.locales] member to dynamically get locales the compiled file size is not
affected. If you do use the [locales] member, all locales will be compiled in and the files size
will become several 10's of MBs.

## Source

All the data are extracted from this repository: https://github.com/unicode-org/cldr-json
The main CLDR data is extracted from this repository: https://github.com/unicode-org/cldr-json.
Additional timezone related data is extracted from https://github.com/unicode-org/cldr
and https://github.com/unicode-org/icu.

- Download date ##DOWNLOAD_DATE##.
- CLDR version ##CLDR_VERSION##, variant: ##CLDR_VARIANT##
- Unicode version ##UNICODE_VERSION##
- TZDB version ##TZDB_VERSION##

## Example

```dart
import 'example/main.dart';
```

## Supported language
## Supported languages/locales

##LANGUAGE_LIST##
##LOCALE_LIST##

Open a [GitHub issue](https://github.com/xvrh/common_locale_data/issues) to propose more
To change the included locales modify the ```tool\config.dart``` file and rerun
the ```generate_code.dart``` and ```generate_readme.dart``` files.
14 changes: 14 additions & 0 deletions dartdoc_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dartdoc:
categories:
"Dates":
markdown: doc/Dates.md
name: "Date and Times"
"Units":
markdown: doc/Units.md
"Languages":
markdown: doc/Languages.md
"Territories":
markdown: doc/Territories.md
"Timezones":
markdown: doc/Timezones.md
showUndocumentedCategories: true
1 change: 1 addition & 0 deletions doc/Dates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Date and time related classes
1 change: 1 addition & 0 deletions doc/Languages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Language, script and variant related data
1 change: 1 addition & 0 deletions doc/Territories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Territory related classes
1 change: 1 addition & 0 deletions doc/Timezones.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Timezone related classes
1 change: 1 addition & 0 deletions doc/Units.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unit related classes
61 changes: 51 additions & 10 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import 'package:common_locale_data/common_locale_data.dart';
import 'package:common_locale_data/ar_eg.dart';
import 'package:common_locale_data/en.dart';
import 'package:common_locale_data/en_gb.dart';
import 'package:common_locale_data/fr.dart';

void main() {
// To preserve tree-shaking, you should explicitly choose the language your want
// The compiler will only retain the languages that are explicitly referenced in your program
// and discard all the others languages. It will make your deployed program smaller.

// Setup the default language for English
cld = CommonLocaleData.en;

// If your app support several languages, dynamically choose the language you want
var currentLanguage = 'en';
cld = const {
'en': CommonLocaleData.en,
'fr': CommonLocaleData.fr,
}[currentLanguage]!;
// from a map you create yourself.
var currentLanguage = 'en-GB';

var locales = const {
'en-GB': CommonLocaleDataEnGB(),
'en': CommonLocaleDataEn(),
'fr': CommonLocaleDataFr(),
'ar-EG': CommonLocaleDataArEG(),
};

var cld = locales[currentLanguage]!;

print(CommonLocaleData.dataDownloadDate);
print(CommonLocaleData.cldrVersion);
print(CommonLocaleData.unicodeVersion);
print(CommonLocaleData.tzdbVersion);

print(cld.locale);
print('');

// Units
print(cld.units.lengthMeter); // meters
Expand All @@ -35,5 +49,32 @@ void main() {
print(cld.territories.countries['US']); // United States

// Languages
print(cld.languages.languages['en']!.name); // English
print(cld.languages['en']!.name); // English

print('');
var zone =
cld.timeZones.get('America/Los_Angeles', dateTime: DateTime(2017))!;

print('code: ${zone.code}');
print('canonicalCode: ${zone.canonicalCode}');
print('ianaCode: ${zone.iana}');
print('shortCode: ${zone.short}');
print('exemplarCity: ${zone.exemplarCity}');
print('country: ${zone.country}');
print('isPrimaryOrSingle: ${zone.isPrimaryOrSingle}');
print('dateRange: ${zone.dateRange}');
print('');

for (var style in TimeZoneStyle.values) {
print(
'${style.name} in own: ${zone.format(style, Duration(hours: -7, minutes: 0))}');
print(
'${style.name} in CA: ${zone.format(style, Duration(hours: -7, minutes: 0), country: 'CA')}');
}

// Demonstrate different timezone names at different times
print(cld.timeZones['America/Buenos_Aires']);
print(cld.timeZones.get('America/Buenos_Aires', dateTime: DateTime(2008)));
print(cld.timeZones
.get('America/Buenos_Aires', dateTime: DateTime(2004, 6, 2)));
}
5 changes: 5 additions & 0 deletions lib/af.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/af.dart' show CommonLocaleDataAf;
5 changes: 5 additions & 0 deletions lib/af_na.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/af_na.dart' show CommonLocaleDataAfNA;
5 changes: 5 additions & 0 deletions lib/am.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/am.dart' show CommonLocaleDataAm;
5 changes: 5 additions & 0 deletions lib/ar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar.dart' show CommonLocaleDataAr;
5 changes: 5 additions & 0 deletions lib/ar_ae.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_ae.dart' show CommonLocaleDataArAE;
5 changes: 5 additions & 0 deletions lib/ar_bh.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_bh.dart' show CommonLocaleDataArBH;
5 changes: 5 additions & 0 deletions lib/ar_dj.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_dj.dart' show CommonLocaleDataArDJ;
5 changes: 5 additions & 0 deletions lib/ar_dz.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_dz.dart' show CommonLocaleDataArDZ;
5 changes: 5 additions & 0 deletions lib/ar_eg.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_eg.dart' show CommonLocaleDataArEG;
5 changes: 5 additions & 0 deletions lib/ar_eh.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_eh.dart' show CommonLocaleDataArEH;
5 changes: 5 additions & 0 deletions lib/ar_er.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_er.dart' show CommonLocaleDataArER;
5 changes: 5 additions & 0 deletions lib/ar_il.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_il.dart' show CommonLocaleDataArIL;
5 changes: 5 additions & 0 deletions lib/ar_iq.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_iq.dart' show CommonLocaleDataArIQ;
5 changes: 5 additions & 0 deletions lib/ar_jo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_jo.dart' show CommonLocaleDataArJO;
5 changes: 5 additions & 0 deletions lib/ar_km.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_km.dart' show CommonLocaleDataArKM;
5 changes: 5 additions & 0 deletions lib/ar_kw.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_kw.dart' show CommonLocaleDataArKW;
5 changes: 5 additions & 0 deletions lib/ar_lb.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_lb.dart' show CommonLocaleDataArLB;
5 changes: 5 additions & 0 deletions lib/ar_ly.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_ly.dart' show CommonLocaleDataArLY;
5 changes: 5 additions & 0 deletions lib/ar_ma.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_ma.dart' show CommonLocaleDataArMA;
5 changes: 5 additions & 0 deletions lib/ar_mr.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_mr.dart' show CommonLocaleDataArMR;
5 changes: 5 additions & 0 deletions lib/ar_om.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_om.dart' show CommonLocaleDataArOM;
5 changes: 5 additions & 0 deletions lib/ar_ps.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_ps.dart' show CommonLocaleDataArPS;
5 changes: 5 additions & 0 deletions lib/ar_qa.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// @nodoc
library;

export 'common_locale_data.dart';
export 'src/data/ar_qa.dart' show CommonLocaleDataArQA;
Loading

0 comments on commit 9a150fb

Please sign in to comment.