Localisation & Translations

The bundle leverages the Symfony Translation component to provide full internationalization (i18n) support for your Progressive Web App. This allows you to create multilingual PWAs that automatically adapt to the user's language preferences.

Overview

The PWA Bundle automatically translates manifest content based on the user's locale. When you provide text values in your configuration (names, descriptions, labels, etc.), they are treated as translation keys that are resolved using Symfony's translation system.

Key benefits:

  • Automatic manifest localization per user locale

  • Support for all Symfony translation formats (YAML, XLIFF, PHP, JSON)

  • Separate manifest files per locale (e.g., site.en.webmanifest, site.fr.webmanifest)

  • Seamless integration with Symfony's translation workflow

  • Full Unicode support for all languages

  • RTL (Right-to-Left) language support

Translation domain: All PWA translations use the pwa domain by default.

How Translation Works

When you configure your PWA manifest:

  1. Text values become translation keys: Values like "app.name" are translation keys, not literal text

  2. Bundle checks for translations: The bundle looks for translations in the pwa domain

  3. Locale-specific manifests generated: A separate manifest is created for each enabled locale

  4. Automatic locale detection: The pwa() Twig function automatically serves the correct manifest based on app.request.locale

Translatable Properties

The following properties are automatically translated by the bundle:

Component
Translatable Properties

Manifest

name, short_name, description

Screenshot

label

Share Target

title, text

Shortcut

name, short_name, description

Widget

name, short_name, description

circle-exclamation
triangle-exclamation

Basic Configuration

Step 1: Enable Locales in Symfony

First, configure the locales your app supports:

See the Symfony Translation documentationarrow-up-right for more information about configuring locales.

Step 2: Configure Locale Placeholder

Add the {locale} placeholder to your manifest public URL:

circle-info

Important: When using the {locale} placeholder, do not manually set the lang parameter. The bundle automatically sets it based on the current locale.

Step 3: Use the pwa() Twig Function

The pwa() Twig function automatically serves the correct localized manifest:

circle-check

Step 4: Create Translation Files

Create translation files for each locale in the pwa domain:

Translation File Formats

The PWA Bundle supports all Symfony translation formats.

YAML is human-readable and easy to edit:

XLIFF Format

XLIFF is ideal for professional translation workflows:

PHP Format

PHP format allows for dynamic translations:

JSON Format

JSON is compatible with JavaScript tooling:

Complete Use Cases

Use Case 1: Multilingual E-Commerce App

Use Case 2: Global News App with RTL Support

circle-check

Use Case 3: SaaS Platform with Region-Specific Content

Note: The {locale} placeholder in screenshot paths allows for locale-specific screenshots.

Generated Manifest Files

When you configure translations with the {locale} placeholder, the bundle generates separate manifest files for each enabled locale.

Example with locales ['en', 'fr', 'de']:

site.en.webmanifest:

site.fr.webmanifest:

site.de.webmanifest:

Translation Workflow

1. Extract Translation Keys

Use Symfony's translation extraction command to find untranslated keys:

2. Translate Content

Option A: Manual Translation

  • Edit YAML/XLIFF files directly

  • Use your preferred text editor

Option B: Professional Translation

  • Export XLIFF files

  • Send to translation service

  • Import translated XLIFF files

Option C: Translation Management Platform

  • Use platforms like Crowdin, Lokalise, or Phrase

  • Import/export via API

  • Collaborative translation workflow

3. Validate Translations

Check for missing translations:

4. Clear Cache

After updating translations, clear the cache:

Testing Translations

1. Test Manifest Generation

Verify that manifests are generated for each locale:

2. Validate Manifest Content

Check that translations are applied correctly:

3. Test in Browser

Manual Testing:

Automated Testing with Puppeteer:

4. Lighthouse Audit

Run Lighthouse with different locales:

Best Practices

1. Use Meaningful Translation Keys

2. Keep Brand Names Consistent

3. Provide Fallbacks

4. Use Translation Parameters for Dynamic Content

While the PWA manifest doesn't support dynamic parameters, you can use them in your translation files:

5. Keep Translations Synchronized

Use a consistent structure across all locales:

6. Test All Locales

Before deploying, verify all locale-specific manifests:

Common Issues

1. Translations Not Applied

Problem: Manifest shows translation keys instead of translated text

Solutions:

2. Wrong Locale Manifest Served

Problem: English manifest served when French is expected

Solutions:

3. Missing Translations for Specific Locale

Problem: Some keys not translated in certain locales

Solutions:

4. Special Characters Not Displaying

Problem: Accented characters or non-Latin scripts display incorrectly

Solutions:

5. RTL Languages Not Working

Problem: Arabic/Hebrew text displays left-to-right

Solutions:

The bundle automatically sets dir: "rtl" for RTL locales (ar, he, fa, ur).

Migration Guide

Migrating from Non-Translated Setup

Before (Hard-coded text):

After (Translation keys):

Migration Steps

  1. Add {locale} placeholder to public_url

  2. Remove manual lang setting (if present)

  3. Replace hard-coded text with translation keys in config

  4. Create translation files for each locale

  5. Configure enabled locales in framework.yaml

  6. Clear cache and test

Troubleshooting Checklist

Before deploying multilingual PWA:

Resources

  • Symfony Translation: https://symfony.com/doc/current/translation.html

  • Translation Component: https://symfony.com/doc/current/components/translation.html

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

  • ICU Message Format: https://unicode-org.github.io/icu/userguide/format_parse/messages/

  • XLIFF Format: https://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html

  • Crowdin: https://crowdin.com/ - Translation management platform

  • Lokalise: https://lokalise.com/ - Localization platform

  • Phrase: https://phrase.com/ - Translation platform

Last updated

Was this helpful?