Spomky-Labs / pwa-bundle

PHP library for generating a full featured PWA manifest
https://pwa.spomky-labs.com
MIT License
28 stars 1 forks source link

Implement localization support in Progressive Web App bundle #182

Closed Spomky closed 3 weeks ago

Spomky commented 3 weeks ago

Updated various modules to support localization, primarily adjusting how manifest files are generated and served. Added new "locales" configuration parameter, made necessary adjustments in manifest and service worker compilers. Additionally, refactored the twig runtime to properly handle localized manifest URLs.

Target branch: Resolves issue #

Spomky commented 3 weeks ago

Ping @tacman.

This PR will allow to generate multiple translated manifest files.

  1. Make sure your application is already configured for multilanguages: https://symfony.com/doc/7.1/translation.html
  2. Declare the locales you want to use in the configuration file. The public URL shoud contain a placeholder {locale}:
pwa:
    manifest:
        enabled: true
        locales:
            - 'en'
            - 'de'
        public_url: 'site.{locale}.webmanifest'
  1. Tell the Twig fonction to serve the localized manifest: {{ pwa(locale=app.request.locale) }}
  2. Translate your keys as usual. THe domain is pwa e.g. pwa+intl-icu.en.xlf
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
  <file source-language="en" target-language="en" datatype="plaintext" original="file.ext">
    <header>
      <tool tool-id="symfony" tool-name="Symfony"/>
    </header>
    <body>
      <trans-unit id="VKDowX61" resname="app.name">
        <source>app.name</source>
        <target>My PWA</target>
      </trans-unit>
    </body>
  </file>
</xliff>
tacman commented 3 weeks ago

Shouldn't the locales default to the framework enabled_locales key? That way we don't have to manually keep them in sync.

https://symfony.com/doc/current/reference/configuration/framework.html#enabled-locales