承接 datalinx/gettext-context 相关项目开发

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

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

datalinx/gettext-context

Composer 安装命令:

composer require datalinx/gettext-context

包简介

Implementation of context functions for the PHP gettext extension

README 文档

README

Implementation of context functions for the PHP gettext extension

Packagist Version Packagist PHP Version Support Packagist Downloads Tests codecov Conventional Commits Packagist License

About

PHP still lacks full support for gettext, because it does not implement the context functions. Until this is sorted out, you can use this package to add context support to your localization efforts.

For example, in English, both persons and products have a "name" attribute. So using a simple gettext:

echo _('Name');

... would yield "Ime" in Slovenian, which is wrong.

To solve this, you can use a context function provided by this package:

echo pgettext('Person', 'Name'); // Echoes "Ime"
echo pgettext('Product', 'Name'); // Echoes "Naziv"

Requirements

  • PHP >= 7.4
  • gettext PHP extension

It can be used on lower versions of PHP, but you won't be able to install it with composer (or run tests).

This package is tested for Linux, but it should work for other systems too. Any Windows and Mac feedback is highly welcome. It would be great if you could make a pull request for testing on those platforms (including the GitHub workflow).

Installing

  1. Download it with composer: composer require datalinx/gettext-context
  2. Include the vendor/datalinx/gettext-context/src/gettext-context.php file when you need it*

* It's not added to the autoload directive, since you might not need or want to always include it in runtime. If you want to always load it, just add the source file to your composer.json autoload files list:

{
    "autoload": {
        "files": [
            "vendor/datalinx/gettext-context/src/gettext-context.php"
        ]
    }
}

Usage

See the documented src/gettext-context.php file for the list of functions and their parameters.

Extracting messages with context support

With xgettext

You can add extra keyword parameters to your xgettext call to include the context functions. For example, this would be used in our package:

xgettext --force-po --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 --keyword=dpgettext:2c,3 --keyword=dnpgettext:2c,3,4 -c -o messages.po tests/Unit/Test.php

With Poedit

If you're using Poedit, add the following keywords in your Catalog > Properties > Sources Keywords:

  • pgettext:1c,2
  • npgettext:1c,2,3
  • dpgettext:2c,3
  • dnpgettext:2c,3,4

Then run the "Update from code" procedure :)

Contributing

If you have some suggestions how to make this package better, please open an issue or even better, submit a pull request.

Should you want to contribute, please see the development guidelines in the DataLinx PHP package template.

Changelog

All notable changes to this project are automatically documented in the CHANGELOG.md file using the release workflow, based on the release-please GitHub action.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

For all this to work, commit messages must follow the Conventional commits specification, which is also enforced by a Git hook.

Credits

  • This answer on Stack Overflow for the implementation.
  • This comment on the PHP documentation for the messages extraction fix.

datalinx/gettext-context 适用场景与选型建议

datalinx/gettext-context 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28.59k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2020 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Context」 「gettext」 「pgettext」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 datalinx/gettext-context 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 datalinx/gettext-context 我们能提供哪些服务?
定制开发 / 二次开发

基于 datalinx/gettext-context 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 28.59k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-09-26