maxoplata/simple-locize

一个通过Locize API处理翻译的轻量级库

v1.0.0 2023-04-21 03:03 UTC

This package is not auto-updated.

Last update: 2024-09-21 07:54:57 UTC


README

Simple Locize 是一个通过Locize API处理翻译的PHP库。Locize是一个允许您轻松管理应用程序翻译的翻译管理系统。

安装

您可以通过Composer安装Simple Locize。在终端中运行以下命令

composer require maxoplata/simple-locize

用法

要使用Simple Locize,首先需要创建一个SimpleLocize类的实例

use Maxoplata\SimpleLocize;

$projectId = 'your-project-id';
$environment = 'your-environment';
$privateKey = 'your-private-key'; // optional

$locize = new SimpleLocize($projectId, $environment, $privateKey);

获取翻译

要获取特定命名空间和语言的翻译,可以使用getAllTranslationsFromNamespace方法

$namespace = 'your-namespace';
$language = 'en';

$translations = $locize->getAllTranslationsFromNamespace($namespace, $language);

这将返回一个包含指定命名空间和语言所有翻译的对象。

翻译一个键

要翻译特定命名空间和语言的特定键,可以使用translate方法

$namespace = 'your-namespace';
$language = 'en';
$key = 'your.key';

$translation = $locize->translate($namespace, $language, $key);

这将返回指定键的翻译,如果没有找到翻译,则返回键本身。

许可

Simple Locize 是开源软件,受 MIT 许可协议 许可。