sealed_languages 0.9.0 copy "sealed_languages: ^0.9.0" to clipboard
sealed_languages: ^0.9.0 copied to clipboard

Provides data for world languages in the form of sealed classes.

example/lib/main.dart

// ignore_for_file: avoid_print

import "package:sealed_languages/sealed_languages.dart";

void main() {
  final indoEuropeanLanguages = NaturalLanguage.list.where(
    (language) => language.family is IndoEuropean,
  );
  // Prints a list of Indo-European languages:
  print(indoEuropeanLanguages);
  // (Language(name: Avestan), Language(name: Afrikaans),
  // ...
  // Language(name: Walloon), Language(name: Yiddish).

  final english = NaturalLanguage.fromCode("Eng");
  print("${english.name}: ${english.codeShort}"); // Prints: "English: EN".

  final russian = NaturalLanguage.fromCodeShort("ru");
  print("${russian.name}: ${russian.code}"); // Prints: "Russian: RUS".

  /// Translations of the language name.
  print(russian.translations.length); // Prints: 120.

  final maybeCzech = NaturalLanguage.maybeFromValue(
    "CZE",
    where: (language) => language.bibliographicCode,
  );

  // This will print: "Native name: čeština".
  print("Native name: ${maybeCzech?.namesNative.first}");

  // Contains functional style methods (when, whenOrNull, map, etc).
  print(maybeCzech?.maybeWhen(langCes: () => "Ahoj!", orElse: () => "Hey!"));

  print(NaturalLanguage.list.length); // Prints: "184".

  /// Translations:

  // Prints Slovak translations of all available languages.
  for (final language in NaturalLanguage.list) {
    print(
      """Slovak name of ${language.name}: ${language.maybeTranslation(const LangSlk())?.name}""",
    );
  }

  // Distinguishes country code in translations.
  print(maybeCzech?.maybeTranslation(const LangPor())?.name); // Prints tcheco.
  print(
    maybeCzech?.maybeTranslation(const LangPor(), countryCode: "PT")?.name,
  ); // Prints "checo".

  // Distinguishes script in translations.
  print(maybeCzech?.maybeTranslation(const LangSrp())?.name); // Prints "чешки".
  print(
    maybeCzech
        ?.maybeTranslation(const LangSrp(), script: const ScriptLatn())
        ?.name, // Prints "češki".
  );
}
9
likes
160
pub points
79%
popularity
screenshot

Publisher

verified publishertsin.is

Provides data for world languages in the form of sealed classes.

Repository (GitHub)
View/report issues

Topics

#languages #language #locale #iso-639 #iso

Documentation

API reference

License

MIT (license)

More

Packages that depend on sealed_languages