Download the PHP package dominservice/data_locale_parser without Composer

On this page you can find all versions of the php package dominservice/data_locale_parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package data_locale_parser

Data Locale Parser

Latest Version Total Downloads

Data Locale Parser is a package for Laravel 5.6 | 5.7 | 5.8 | 6. | 7. | 8. | 9.| 10.| 11., which lists all countries, currencies and languages, with names and ISO 3166-1 codes in all languages and data formats.

Installation

Require package via Composer: composer require dominservice/data_locale_parser

Usage

Declare ussage

(...)

(...)

Get all countries

Get all currencies

Get all Languages

All lists return a collection


Get country

Get currency

Get Language

Format an address based on country-specific format

Address Format Keys

The following keys can be used in the address data array for the formatAddress function:

Key Description Example
address Primary address line (street address) 1234 Some St.
address2 Secondary address line Floor #67
address3 Tertiary address line Unit #123
city City name San Francisco
subdivision State, province, or region CA
postalCode Postal or ZIP code 94105
countryCode ISO 3166-1 Alpha-2 country code (required) US

The function will format the address according to the country-specific format based on the countryCode. If a specific country format is not available, it will use the international format.

Additional Address Parameters

The formatAddress function accepts several additional parameters beyond the basic address data:

Parameter Type Description Example
name string Person's name to include at the beginning of the address John Doe
companyName string Company name to include in the address Example Company Ltd.
vatNumber string VAT identification number GB123456789
phoneNumber string Contact phone number +1 (123) 456-7890
additionalFields array Array of additional text lines to include ['Customer ID: 12345']

These additional parameters will be included in the formatted address in the following order:

  1. Name (if provided)
  2. Company name (if provided)
  3. VAT number (if provided, prefixed with "VAT: ")
  4. Standard address lines (formatted according to country format)
  5. Phone number (if provided)
  6. Any additional fields (in the order they appear in the array)

If you have collected all data, you make use this code

Then You get

You may get one country full data

Language Handling Middleware

This package includes a middleware for handling language detection from URL paths and request headers. This allows you to create routes with language prefixes (e.g., /en/page, /pl/page) and automatically set the application locale based on the URL or header.

Configuration

Publish the configuration file:

This will create a config/data_locale_parser.php file with the following options:

Usage

Register the middleware in your app/Http/Kernel.php file:

Cookie Encryption

By default, Laravel encrypts all cookies. If you're using cookies for language storage (use_cookies set to true), you need to exclude the language cookie from encryption. Otherwise, the middleware might not be able to read the cookie correctly.

Add the language cookie name to the $except array in your app/Http/Middleware/EncryptCookies.php file:

If you've changed the cookie name in your configuration, make sure to use that name instead of 'language'.

Cookie Handling

This package sets cookies directly on the response object to ensure they are properly included in the response. The package automatically applies the web middleware group to its routes to ensure that cookies work correctly.

Apply the middleware to your routes:

How It Works

  1. URL Detection: The middleware checks if the first segment of the URL path is a valid language code. For API routes (URLs starting with a prefix defined in api_prefixes), it checks the second segment.

  2. Header Detection: If URL detection is disabled or fails, the middleware checks the request header specified in the configuration.

  3. Default Locale: If no language is detected from the URL or header, the middleware uses the default locale specified in the configuration.

  4. Cookie Storage: If use_cookies is enabled, the language preference will be stored in a cookie. This allows the language to persist across requests without showing it in the URL. For non-API routes, the middleware will check for the language in the cookie before checking the URL.

Changing the Language

The package automatically registers a route for changing the language. By default, this route is /change-language/{language}, but you can customize it in the configuration.

To create a language switcher in your application, you can use the following example:

When a user clicks on a language link, the following happens:

  1. The language is validated against the allowed locales and the language database.
  2. If valid, the language is set as the application locale.
  3. If use_cookies is enabled, the language preference is stored in a cookie.
  4. The user is redirected back to the previous page using one of the following methods:
    • Route Name-Based Redirection: If the previous page has a named route with a locale prefix (e.g., en.contact), the controller will replace the locale in the route name and redirect to the new route with the same parameters. This allows for path translation (e.g., /kontakt to /contact) when your routes are properly localized.
    • URL Segment Manipulation: If route name-based redirection fails or the route doesn't have a name, the controller falls back to URL segment manipulation:
      • If use_cookies is enabled, the language prefix is removed from the URL.
      • If use_cookies is disabled, the language prefix is updated or added to the URL.

This allows you to create a seamless language switching experience for your users, with or without showing the language in the URL, and with support for path translation when using named routes.

Setting Up Localized Routes

To take advantage of the route name-based redirection and path translation, you need to set up your routes with locale prefixes in their names. Here's an example:

With this setup, when a user switches from Polish to English while on the /pl/kontakt page, they will be redirected to /en/contact instead of just changing the language prefix.

Helper Functions

This package includes several helper functions to make working with localized routes and URLs easier. These functions are automatically loaded when you install the package.

RTL Detection

Checks if a locale is RTL (Right-to-Left). If no locale is provided, it uses the current application locale.

You can configure which locales are considered RTL in the config/data_locale_parser.php file:

Route Translation

Gets a translated route key for a specific locale. This is useful for translating route names or segments.

Localized Routes

Generates a URL to a named route for the current locale.

Generates a URL to a named route for a specific locale.

Route Checking

Checks if the current route name matches any of the given patterns for the current locale.

URL Localization

Gets the URL for the current page in a different locale. This function tries to use route name-based redirection first, and falls back to URL segment manipulation if that fails.

Examples

For more advanced usage examples, check out the examples directory. It contains sample code demonstrating various features of the library, including:

Credits


All versions of data_locale_parser with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.3
ext-intl Version *
ext-mbstring Version *
laravel/framework Version ^5.6|^5.7|^5.8|^6|^7|^8|^9|^10|^11|^12
arcreative/php-address-format Version ^0.0.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package dominservice/data_locale_parser contains the following files

Loading the files please wait ....