Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for TimeZone information + General enhancements #11

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0a2da43
Updated fetch_data to include timezone information
Aug 17, 2024
6236a1d
Update data files to latest CLDR (45)
Aug 17, 2024
c77f56f
Include version numbering in README.md
Aug 17, 2024
4fc3a15
Dynamically fetch supported languages
Aug 17, 2024
705cd73
Remove CLDR data from repository
Aug 17, 2024
2aea4d6
Split available locale fetching to separate file
Aug 17, 2024
94315b2
Fixed some incompatibilities with CLDR data v45
Aug 17, 2024
c2e9dd1
Generated code with CLDR v45
Aug 17, 2024
a603ff7
Delete generated dart files before creation
Aug 17, 2024
bbeac1e
Remove fixed supported_locales
Aug 17, 2024
3a852a2
Make full or modern customizable
Aug 17, 2024
c592fdd
updated syntax to dart 3
Aug 17, 2024
881ad06
Added support for scripts & variants
Aug 17, 2024
60389fd
Supported locales to config file
Aug 24, 2024
964a25e
Properly named "locale" instead of language, script or variant
Aug 24, 2024
33a0ab2
Implemented TimeZones
Aug 24, 2024
343489a
Add versions CLDR/Unicode/TZDB versions to generate code
Aug 26, 2024
8033030
Fetch additional TZDB data needed to get territories for timezones
Aug 26, 2024
1a746fd
Cleaned up code and added documentation
Aug 31, 2024
07dc890
Further cleaned up and added documentation
Aug 31, 2024
09fd506
Corrected tests for removal of global cld variable
Aug 31, 2024
bdcaae4
Added timezone toString function
Aug 31, 2024
26031e2
Added timezone tests
Aug 31, 2024
7cf51d2
Added localeNames and locale maps
Aug 31, 2024
d8f43d6
Moved full or modern choice for CLDR to config.dart
Aug 31, 2024
084b38e
Added ignore for 'exemplarCity-alt-secondary'
Aug 31, 2024
15e7812
Improve compile times by no longer include all locales in common_loca…
Aug 31, 2024
16171de
Generated modern data for all locales
Aug 31, 2024
2157ba0
Include CLDR variant
Aug 31, 2024
7eb001f
Add all available locales
Aug 31, 2024
cc6b77f
Updated version
Aug 31, 2024
b7dc3f1
- Updated generation for supporting CommonLocaleDataAll
Sep 1, 2024
676e2c4
Regenerated locale data
Sep 1, 2024
7263d27
Updated tests
Sep 2, 2024
3cc1282
Cleanup naming of helper functions
Sep 2, 2024
b8d65ef
Completed detection of primary or single timezone
Sep 2, 2024
63473be
Implemented time zone non-location formatting
Sep 6, 2024
104d24e
Added support for short timezone codes
Sep 6, 2024
c761d9d
Improved timezone name formatting to align closer with UCI4x
Sep 7, 2024
38bd1cf
Added territoryCode
Sep 8, 2024
e659871
Removed dead code from example
Sep 14, 2024
04db22d
Removed unused import from test
Sep 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ pubspec.lock
!.gitignore
!.github
!.pubignore

# Downloaded CLDR data
/tool/data/
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.
484 changes: 466 additions & 18 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;
5 changes: 5 additions & 0 deletions lib/ar_sa.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_sa.dart' show CommonLocaleDataArSA;
Loading