Skip to content

PiperLang is a compact and efficient PHP framework designed to provide localization capabilities for your web application

License

Notifications You must be signed in to change notification settings

JacobJoergensen/PiperLang

Repository files navigation

PiperLang

PiperLang is a compact and efficient PHP framework designed to provide localization capacities for your web application. With features supporting cookie and session-based locale detection, dynamic pluralization, variable substitution in translations, and number, currency and date formatting in accordance with the set locale.


Craft your web app with precision, localize with ease.
Explore PiperLang docs »

Report bug · Request feature · License · Changelog



ℹ️ PHP Version: The development cycle of PiperLang operates on PHP 8.3. For optimal compatibility and performance, we recommend using this version when working with PiperLang.


Features

  • Localization Support: PiperLang provides robust support for localization, allowing developers to easily translate their web applications into different languages.
  • Automatic Locale Detection: The framework can automatically detect the user's preferred locale based on their browser settings or session/cookie preferences.
  • Flexible Locale Management: Developers can set, switch, and manage locales dynamically, either based on user preferences or default settings.
  • Translation with Pluralization: PiperLang facilitates translation with pluralization, ensuring accurate representation of phrases based on count variations.
  • Variable Replacement in Translations: Developers can easily replace placeholders in translated strings with provided variables, enhancing flexibility in localization.
  • Locale File Management: The framework handles loading and processing of locale files, ensuring proper validation of content and support for JSON format.
  • Number and Currency Formatting: PiperLang offers utilities for formatting numbers and currency amounts according to the current locale, improving user experience in diverse regions.
  • Date Formatting: Developers can format dates according to the current locale, with options for different date formats such as short, medium, long, and full.
  • Customizable Hooks: The framework allows developers to define and execute custom hook actions at various stages, providing extensibility for integrating additional functionalities.
  • Debugging Support: PiperLang includes debugging features to help developers identify and resolve issues related to locale management, file loading, and formatting.

Quick Start

1. Download PiperLang

  • You can download the PiperLang framework from its GitHub repository or via Composer. If you're using Composer, you can simply run: composer require piperlang/piperlang

2. Initialize PiperLang

  • Once downloaded, include the framework in your PHP file where you intend to use localization:

    require_once 'path/to/vendor/autoload.php'; // If you've installed via Composer
    // or
    require_once 'path/to/PiperLang.php'; // If you've downloaded the framework directly
  • Then call the core class by doing:

    use PiperLang\PiperLang;
  • After that we can create a new instance of PiperLang like so:

    $piper = new PiperLang();

3. Simple Example

  • Now we can start playing around with PiperLang, this is a super simple example of it.

    $piper->supported_locales = ['en', 'da']; // Modifying supported locales
    $piper->locale_path = '/app/assets/locales/'; // Modifying the path for the locale files
    $piper->debug = true; // Set the debug mode to true
    
    $piper->setLocale($piper->detectBrowserLocale()); // Set locale based on the browser locale
    
    echo "Current Locale: " . $piper->getLocale() . "\n"; // To see the current locale
    
    $localeNodes = $piper->loadFile($piper->detectBrowserLocale()); // Load the locale file based on the browser locale
    
    if (isset($localeNodes['welcome'])) {
        echo "Welcome Message: " . $localeNodes['welcome'] . "\n";
    } else {
        echo "No translation found for 'welcome' key in " . $piper->current_locale . " locale.\n";
    }
  • See more examples by clicking here!

Status

ci codecov

Contributing

We welcome contributions to PiperLang! Whether you want to report a bug, request a feature, or submit a pull request with code changes, your input is highly valued. Please see the CONTRIBUTING

License

Thank you for using PiperLang!

This project is licensed under the terms of the MIT License, allowing you to use, modify, and distribute the software freely. For details, please see the LICENSE file.


About

PiperLang is a compact and efficient PHP framework designed to provide localization capabilities for your web application

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published