承接 gokhankurtulus/multilanguage 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gokhankurtulus/multilanguage

最新稳定版本:1.0.0

Composer 安装命令:

composer require gokhankurtulus/multilanguage

包简介

A simple PHP library for multi-language projects.

关键字:

README 文档

README

License: MIT PHP Version Release

A simple PHP library for multi-language projects.

Installation

You can install the library using Composer. Run the following command:

composer require gokhankurtulus/multilanguage

Usage

You need to create a directory first and create the desired languages in this directory in JSON format. Example JSON files are provided below.

Example Hierarchy

project
   ├── Lang
   │    ├── de.json
   │    ├── en.json
   │    └── tr.json
   └── index.php

en.json

{
  "Hello": "Hello #name# $lastname$",
  "Homepage": "Homepage"
}

tr.json

{
  "Hello": "Selam #name# $lastname$",
  "Homepage": "Anasayfa"
}

de.json

{
  "Hello": "Hallo #name# $lastname$",
  "Homepage": "Startseite"
}

index.php

use MultiLanguage\MultiLanguage;

MultiLanguage::setDirectoryPath(__DIR__ . DIRECTORY_SEPARATOR . "Lang");
MultiLanguage::setAllowedLanguages(["en", "tr", "de"]);
MultiLanguage::setDefaultLanguage("en");
MultiLanguage::setCurrentLanguage("tr");

// Output will be "Homepage" because $lang parameter is set to 'en'.
// If $lang is null or empty tries to get current language
// if current is not defined then tries to get default language
// if both not defined and $lang is not given throws an LanguageException
echo MultiLanguage::translate('Homepage', 'en');

// Output will be "Anasayfa" because current language is 'tr'.
echo MultiLanguage::translate('Homepage');

// Output will be "Hallo John Doe".
// Specify unique keys in the language file then you can manipulate them.
// In this example, if your key is located many places in string it will change all of them.
echo MultiLanguage::translate('Hello', 'de', ['#name#' => 'John', '$lastname$' => 'Doe']);

Public Methods

MultiLanguage::translate(string  $text, ?string $lang = null, array $replacement = []);

MultiLanguage::getDirectoryPath();
MultiLanguage::setDirectoryPath(string $directoryPath, bool $force = false);

MultiLanguage::getAllowedLanguages();
MultiLanguage::setAllowedLanguages(array $languages);
MultiLanguage::isAllowedLanguage(string $lang);

MultiLanguage::getDefaultLanguage();
MultiLanguage::setDefaultLanguage(string $lang);

MultiLanguage::getCurrentLanguage();
MultiLanguage::setCurrentLanguage(string $lang);

License

MultiLanguage is open-source software released under the MIT License. Feel free to modify and use it in your projects.

Contributions

Contributions to MultiLanguage are welcome! If you find any issues or have suggestions for improvements, please create an issue or submit a pull request on the GitHub repository.

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-31