Skip to content

Commit

Permalink
chore: sealed_languages v2.0.1 (#287)
Browse files Browse the repository at this point in the history
* refactor: update generics in common name methods

* refactor(ci): update publish workflows

* fix(tests): specify generic type for options in tests

* docs: bump `sealed_languages` to v2.0.1, enhance documentation

* fix(ci): update runner version to ubuntu-latest in backup workflow
  • Loading branch information
tsinis authored Jan 24, 2025
1 parent f52b1f3 commit 8d37e72
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
mirror-to-gitlab:
name: 💾 Backup to GitLab
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: 📚 Git checkout
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/publish_packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ jobs:
permissions:
id-token: write
with:
package_name: ${{ fromJSON(format('["{0}"]', github.ref_name))[0] }}
tag: ${{ github.ref_name }}
7 changes: 2 additions & 5 deletions .github/workflows/publish_to_pub_workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name: publish_to_pub_workflow
on:
workflow_call:
inputs:
package_name:
required: true
type: string
tag:
required: true
type: string
Expand All @@ -19,15 +16,15 @@ jobs:
outputs:
package_name: ${{ steps.extract_name.outputs.value }}
steps:
- name: Extract package name
- name: 📦 Extract package name
id: extract_name
shell: bash
run: |
PACKAGE_NAME=$(echo "${{ inputs.tag }}" | sed 's/-v[0-9]\+\.[0-9]\+\.[0-9]\+//')
echo "value=$PACKAGE_NAME" >> $GITHUB_OUTPUT
echo "Extracted package name: $PACKAGE_NAME"
- name: Set working directory
- name: 📂 Set working directory
run: echo "relative_path=packages/${{ steps.extract_name.outputs.value }}" >> $GITHUB_ENV

- name: 📚 Git checkout
Expand Down
14 changes: 13 additions & 1 deletion packages/sealed_languages/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
## 2.0.1

REFACTOR

- Improved generics handling in localization methods.
- Update and use stable L10N package.

DOCUMENTATION

- Improved documentation and example.
- Fixed typos in the README.

## 2.0.0

🎉 Second anniversary and new major release!

NEW FEATURES

- Introduced new methods for working with common names and common name maps: `commonNamesMap` on ISO collections and `commonNameFor`/`maybeCommonNameFor` on ISO objects. These methods are significantly faster than the old `translations` - related methods because they work directly with locale-specific maps instead of iterating through all translations of each ISO object.
- The `translations` getter is now a real computed field. This means it will only generate the translations when they are requested, rather than storing them all in memory. It's recommended to cache the results of the getter to avoid redundant calculations. Because of that - `translation` and `maybeTranslation` methods are no longer recommended for retriving localization data.
- The `translations` getter is now a real computed field. This means it will only generate the translations when they are requested, rather than storing them all in memory. It's recommended to cache the results of the getter to avoid redundant calculations. Because of that - `translation` and `maybeTranslation` methods are no longer recommended for retrieving localization data.
- The `commonNamesCacheMap` is deprecated because it relies on the memory-intensive `translations` getter.
- New localization delegates on `IsoTranslated` objects simplify complex queries for object localizations.
- Bool getters on `IsoStandardized` objects can now be applied to null values. For example, `maybeIso.isRus` will return `false` if `maybeIso` is null, without the need for additional null-checks.
Expand Down
1 change: 1 addition & 0 deletions packages/sealed_languages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ For more usage examples, please see the `/example` folder.
- **Type-safe**: The contracts and types in this package are exceptionally strong, ensuring that your code is strongly typed and well-defined.
- **High code coverage**: The code in this package has 100% code coverage, with more than 1533 tests, 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.
- **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.
- **Industry adopted**: This package is actively used in production by numerous European companies, ensuring its efficacy and robustness in real-world scenarios.
- **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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ extension IsoTranslatedIterableExtension<
/// );
/// print(map[const LangAfr()]); // "Afrikaans"
/// ```
Map<I, String> commonNamesMap({required LocaleMappingOptions<L> options}) =>
Map<I, String> commonNamesMap<B extends L>({
required LocaleMappingOptions<B> options,
}) =>
isEmpty ? const {} : first.l10n.commonNamesMap(this, options: options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ extension TranslatedExtension<T extends TranslatedName, L extends BasicLocale,
/// // Returns German common name for the language or `orElse` if not found.
/// final name = language.commonNameFor(const BasicLocale(LangDeu()));
/// ```
String commonNameFor(
L mainLocale, {
L? fallbackLocale,
String commonNameFor<B extends L>(
B mainLocale, {
B? fallbackLocale,
bool useLanguageFallback = true,
String orElse = "",
}) =>
l10n.commonNamesMap(
{this},
options: LocaleMappingOptions<L>(
options: LocaleMappingOptions<B>(
mainLocale: mainLocale,
fallbackLocale: fallbackLocale,
useLanguageFallback: useLanguageFallback,
Expand All @@ -86,15 +86,15 @@ extension TranslatedExtension<T extends TranslatedName, L extends BasicLocale,
/// // Returns German common name for the language or `null` if not found.
/// final name = language.maybeCommonNameFor(const BasicLocale(LangDeu()));
/// ```
String? maybeCommonNameFor(
L mainLocale, {
L? fallbackLocale,
String? maybeCommonNameFor<B extends L>(
B mainLocale, {
B? fallbackLocale,
bool useLanguageFallback = true,
String? orElse,
}) =>
l10n.commonNamesMap(
{this},
options: LocaleMappingOptions<L>(
options: LocaleMappingOptions<B>(
mainLocale: mainLocale,
fallbackLocale: fallbackLocale,
useLanguageFallback: useLanguageFallback,
Expand Down Expand Up @@ -129,7 +129,10 @@ extension TranslatedExtension<T extends TranslatedName, L extends BasicLocale,
/// orElse: const LangEng(), // Default language if no translation is found.
/// );
/// ```
T translation(L locale, {NaturalLanguage orElse = const LangEng()}) =>
T translation<B extends L>(
B locale, {
NaturalLanguage orElse = const LangEng(),
}) =>
maybeTranslation(locale) ??
translations.firstWhere((l10n) => l10n.language == orElse);

Expand Down Expand Up @@ -157,7 +160,10 @@ extension TranslatedExtension<T extends TranslatedName, L extends BasicLocale,
/// // language if no matching translation is found.
/// );
/// ```
T? maybeTranslation(L? locale, {bool useLanguageFallback = true}) {
T? maybeTranslation<B extends L>(
B? locale, {
bool useLanguageFallback = true,
}) {
if (locale == null) return null;
final filtered = List<T>.unmodifiable(
translations.where((l10n) => l10n.language == locale.language),
Expand Down
4 changes: 2 additions & 2 deletions packages/sealed_languages/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2.0.0
version: 2.0.1
name: sealed_languages
description: Provides data for world languages in the form of sealed classes.
maintainer: Roman Cinis
Expand All @@ -23,7 +23,7 @@ environment:
sdk: ^3.6.0

dependencies:
l10n_languages: ^0.1.0
l10n_languages: ^1.0.0

dev_dependencies:
_sealed_world_tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main() => group("IsoTranslatedIterableExtension", () {
group("commonNamesMap", () {
performanceTest("on empty list should return empty map", () {
final map = <NaturalLanguage>{}.commonNamesMap(
options: const LocaleMappingOptions(),
options: const LocaleMappingOptions<BasicLocale>(),
);
expect(map, isEmpty);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main() => group("TranslatedExtension", () {
group("maybeTranslation", () {
test(
"should return null on null locale",
() => expect(kongo.maybeTranslation(null), isNull),
() => expect(kongo.maybeTranslation<BasicLocale>(null), isNull),
);

test(
Expand Down

0 comments on commit 8d37e72

Please sign in to comment.