Download the PHP package mmdm/sim-i18n without Composer

On this page you can find all versions of the php package mmdm/sim-i18n. 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 sim-i18n

Simplicity I18n

A library for internationalization.

Install

composer

Or you can simply download zip file from github and extract it, then put file to your project library and use it like other libraries.

Just add line below to autoload files:

and you are good to go.

How to use

Description

It provides two kind of translate class:

Both have same method but in different usage

  1. If you use DIC (Dependency Injection Container) or can pass translate instance to other part of your application, then use simple one.
  2. Otherwise use singleton for convenient.

First one is recommended

For language, it recommend ISO 639-1 language codes that can access to them through ISOLanguageCodes class.

Test beside testing purposes, also have example purposes. See how to use methods there.

Available functions

Translate

createLanguageFile(string $language, string $directory)

This method will create an empty language file in $directory.

Note: $language should be just the file name like en, fr etc. Note: If directory or file is exists, it do nothing. Note: Please use ISOLanguageCodes class for better results.

setLocale(string $language)

Set locale language to get translates from that file

Note: This is actually the language file name(Just file name not directory name).

Default is en

getLanguage(): string

Get translate language that has been set from setLocale method.

Note: If you use ISO 639-1 standard, you can set html language with this method easily.

setTranslateDir(string $directory)

Set language directory

Note: Just specify directory not file.

getTranslateFromFile(string $filename, bool $fresh = false): array

Get all translates from a language file.

Basically after reading a language file, it will be cached by library but if you need to read it another time, pass true as $fresh variable value.

itIsRTL()

You can specify it is a rtl language that is using. Purpose of this method is to have specific reaction according to rtl in your view.

isRTL(): bool

Return true if language is rtl otherwise return false.

Note: By default it will check in ISOLanguageCodes class in rtl languages to check it is a rtl language or not. Note: If you set it is a rtl language through itIsRTL method, it will be rtl in any condition even if it's not.

translate(string $key, $fileOrValue = null, array $value = [])

This is the main method to translate to language you specified.

$key is the key that sets in language file.

In $fileOrValue parameter you can pass translate filename (without specify directory) or directory + filename by adding file: prefix to string or if you are happy with previous setting, and need to pass values to translate string, pass it here instead of third parameter.

Note: If $key could not translate, $key will return.

translateChoice(string $key, int $count, $fileOrValue = null, array $value = [])

Exactly like translate method but you can pluralization on it.

Example 1

If your file has structure like this:

you can access a translate like:

You can use placeholder for your translates and replace that placeholder by passing and array of key(as placeholder) and value(as value of placeholder) through $value parameter.

If you need to access a multidimensional array inside you translate file, you can pass $key as a dot separated string to get what you want:

Example 2

If you have multiple files with some translations like:

file number 1:

file number 2:

Now to use translation you can do following things:

Example 3

Assume we have below translation file:

now to get it according to number of items, call translateChoice method.

as you can see we did not pass count to translate but it could be used internally.

Also if you pass count as third or forth parameter, it'll be replaced by actual count.

ISOLanguageCodes

static isInLanguageCode(string $code): bool

Check if language is in ISO 639-1 languages or not.

static isRtlLanguage(string $code): bool

Check if a language is rtl or not.

Rtl language list for now are:

License

Under MIT license.


All versions of sim-i18n with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 mmdm/sim-i18n contains the following files

Loading the files please wait ....