Direction and Language

The dir and lang properties define the text direction and primary language of your PWA, ensuring proper display, accessibility, and localization for international audiences.

Purpose

Language and direction settings enable:

  • Proper text rendering: Correct text flow for different writing systems

  • Accessibility: Screen readers use correct pronunciation and voice

  • Search optimization: Search engines understand content language

  • User experience: Interface elements adapt to language/direction

  • Localization: Foundation for multi-language support

Configuration

/config/packages/pwa.yaml
pwa:
    manifest:
        enabled: true
        dir: "ltr"       # Text direction
        lang: "en"       # Primary language (ISO 639-1)
circle-info

Important: Manifest dir and lang should match your HTML <html> tag attributes for consistency.

<html dir="ltr" lang="en">

The dir Parameter

The dir property specifies how text flows in your application.

Available Values

ltr (Left-to-Right)

Default for most languages. Text flows from left to right.

Used for:

  • English, Spanish, French, German

  • Most European languages

  • Asian languages (Chinese, Japanese, Korean)

  • Most world languages

Examples: "Hello World" displays as:

rtl (Right-to-Left)

Text flows from right to left.

Used for:

  • Arabic (العربية)

  • Hebrew (עברית)

  • Persian/Farsi (فارسی)

  • Urdu (اردو)

Examples: "مرحبا بالعالم" (Hello World) displays as:

auto (Automatic)

Determines direction based on content. Rarely used in manifests.

Used for:

  • Mixed-direction content

  • User-generated content with multiple languages

  • Dynamic content where direction varies

circle-exclamation

The lang Parameter

The lang property declares the primary language using ISO 639-1 language codes.

Language Code Format

Common Language Codes

European Languages

Asian Languages

Right-to-Left Languages

Other Languages

Practical Examples

English (United States)

Arabic Application

French (France)

Chinese (Simplified)

Hebrew Application

Spanish (Mexico)

Multi-Language Support

Translatable Manifest Properties

The PWA Bundle supports translatable manifest properties:

Serving Different Manifests

You can serve different manifests based on user locale:

HTML Integration

Matching HTML and Manifest

Your HTML should match manifest settings:

Symfony Twig Integration

CSS Considerations

RTL-Specific Styles

When supporting RTL, adjust your CSS:

Logical CSS Properties

Prefer logical properties for better RTL support:

Accessibility Impact

Screen Readers

Correct lang attribute helps screen readers:

  • Use proper pronunciation

  • Select correct voice

  • Apply language-specific rules

Text-to-Speech

Browsers use lang to determine:

  • Voice selection

  • Pronunciation rules

  • Speech synthesis parameters

SEO Considerations

Language Targeting

Search engines use lang for:

  • Geo-targeting search results

  • Language-specific indexing

  • Serving content to appropriate audiences

hreflang Relationship

Coordinate with HTML hreflang tags:

Platform Behavior

iOS/Safari

  • Respects dir for interface layout

  • Uses lang for system integration

  • May override with user language preferences

Android/Chrome

  • Strong dir support

  • Automatic UI mirroring for RTL

  • System language integration

Desktop Browsers

  • Full dir and lang support

  • CSS :dir() pseudo-class support

  • Proper text rendering

Common Mistakes

1. Mismatched Direction and Language

Fix:

2. Missing Language Region

Fix:

3. Invalid Language Codes

Fix:

4. HTML/Manifest Mismatch

Fix: Ensure both match or dynamically generate manifest.

5. Forgetting RTL CSS

Fix: Use logical properties or RTL-specific rules.

Testing

1. Test in DevTools

2. Test with Screen Readers

  • NVDA (Windows)

  • JAWS (Windows)

  • VoiceOver (Mac/iOS)

  • TalkBack (Android)

Verify correct language voice is used.

3. Visual Testing

For RTL languages:

  • UI should mirror (buttons, menus on opposite side)

  • Text should flow right-to-left

  • Scrollbars should appear on left

4. Test Language Detection

Language Code Reference

ISO 639-1 Standard

Language codes follow ISO 639-1 (two letters):

  • https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

Region Codes

Region codes follow ISO 3166-1 alpha-2:

  • https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

Complete Format

Summary

Direction and language best practices:

  • ✓ Set lang using ISO 639-1 codes

  • ✓ Use ltr for most languages, rtl for Arabic/Hebrew/Persian

  • ✓ Match HTML dir and lang attributes

  • ✓ Include region codes when relevant (e.g., en-US vs en-GB)

  • ✓ Support RTL with appropriate CSS

  • ✓ Test with screen readers

  • ✓ Use translatable manifest properties for multi-language apps

  • ✗ Don't use invalid language codes

  • ✗ Don't mismatch direction and language

  • ✗ Don't forget to test RTL layouts

  • ✗ Don't ignore HTML/manifest consistency

Last updated

Was this helpful?