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

Support for localization in PkPass files #8

Open
ueman opened this issue Jun 21, 2024 · 1 comment
Open

Support for localization in PkPass files #8

ueman opened this issue Jun 21, 2024 · 1 comment
Labels
package: passkit_ui Issues relevant for the "passkit_ui" package package: passkit Issues relevant for the "passkit" package prio: high High prioritity

Comments

@ueman
Copy link
Owner

ueman commented Jun 21, 2024

Text can be localized, but images can be localized too.

PkPass docs for localizations (text and images):

Docs for .strings file format description:

.strings files are UTF-16 not UTF-8, so the files have to be read like this StackOverflow post suggests. This issue dart-lang/core#266 contains some hints too.


There are various approaches to parsing a .strings file:

  • use a regex (I believe strings files for pkpasses technically can't have placeholders)
  • write a custom parser using petiteparser
  • naive custom string parsing

Personally, I would like to see a custom parser based on petiteparser with all the bells and whistles, but I think using a RegEx at first should be sufficient.


The API could look like one of the following examples:

class PkPass {
  String getTranslated(String key, Locale locale) { ... }
}

// and then you can use it something like this:

PkPass pass = ...;
pass.getTranslated(pass.pass.description, locale);

With intl


pass.pass.description;
// provide a localized getter that makes use of Intl.defaultLocale or is alternatively set somehow
pass.pass.descriptionLocalized;

This paragraph is only relevant for passkit_UI

Language fallback rules (should be applied on a per field basis):

  1. No translations -> Nothing gets translated
  2. The users' language gets chosen if available (e.g. de_DE)
  3. The users' language without country code gets chosen if available (e.g. de instead of de_DE)
  4. Otherwise, fallback to what's reported via PlatformDispatcher.locales (while skipping already tried languages)
    • First the languages are tested with country codes (de_DE), then without (just de)
  5. If a translation is missing, fall back to the translation key

Formatted values like dates, numbers, etc are always localized to the users' current language (as described here)


The default localized value should be https://api.dart.dev/stable/3.4.4/dart-io/Platform/localeName.html on dart:io and whatever browser equivalent there is. On Flutter it should use the Localization.of().locale as default.

@ueman ueman added the package: passkit Issues relevant for the "passkit" package label Jun 21, 2024
@ueman ueman added package: passkit_ui Issues relevant for the "passkit_ui" package prio: high High prioritity labels Jun 30, 2024
@ueman
Copy link
Owner Author

ueman commented Aug 4, 2024

This is now mostly usable, albeit not automatic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: passkit_ui Issues relevant for the "passkit_ui" package package: passkit Issues relevant for the "passkit" package prio: high High prioritity
Projects
None yet
Development

No branches or pull requests

1 participant