pfcode/symfony-i18n-comparator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

pfcode/symfony-i18n-comparator

Composer 安装命令:

composer require pfcode/symfony-i18n-comparator

包简介

Utility for comparison of duplicated translation files in Symfony projects.

README 文档

README

Utility for making a comparison of duplicated translation files in Symfony projects.

Use case

The case this util resolves is very specific - it's intended to help find differences between translation files belonging to the same domain and language, but saved in different formats (messages.en.xlf and messages.en.yml, for example).

Note: Such differences should not occur under usual circumstances when using symfony/translation component. Please see the Example section below and check if this bundle actually solves your problem.

Installation

You can add this bundle into your Symfony project using Composer:

composer require pfcode/symfony-i18n-comparator

This bundle requires at least Symfony 4.4 or 5.0 and PHP 7.1 or later and it's not intended to be used on production environments.

Example

Let's say you have two translation files in your project, that belong to the same domain and are in the same language:

translations/messages.en.xlf:

<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
    <file source-language="fr" target-language="en" datatype="plaintext" original="file.ext">
        <header>
            <tool tool-id="symfony" tool-name="Symfony"/>
        </header>
        <body>
            <trans-unit id="XXXXXXX" resname="nav.home">
                <source>nav.home</source>
                <target>Dashboard</target>
            </trans-unit>
            <trans-unit id="YYYYYY" resname="nav.login">
                <source>nav.login</source>
                <target>Sign In</target>
            </trans-unit>
            <trans-unit id="ZZZZZZ" resname="nav.logout">
                <source>nav.logout</source>
                <target>Logout</target>
            </trans-unit>
        </body>
    </file>
</xliff>

translations/messages.en.yml:

nav:
  home: 'Home'
  login: 'Sign In'
  logout: 'Sign Out'
  search: 'Search something...'

These translation files obviously have some differences. One of them has nav.search key missing and other messages have different values. Comparing those files in a text editor would be painful.

To compare them at the logical level (translation keys, that is), you can use a command provided by this bundle:

bash-4.4# bin/console i18n-comparator:find-conflicts --translations-dir=translations
+---------------------+-- messages.en ------+-----------------+
| Key                 | messages.en.yml     | messages.en.xlf |
+---------------------+---------------------+-----------------+
| messages.nav.home   | Home                | Dashboard       |
| messages.nav.logout | Sign Out            | Logout          |
| messages.nav.search | Search something... |                 |
+---------------------+---------------------+-----------------+

With this command, searching for differences across various translation formats should be a lot easier.

Supported translation formats

This bundle registers a ComparatorFactory service and passes references to all known translation loaders (all services tagged by translation.loader) to it. So it supports all formats that your Symfony installation already does.

License

This project is distributed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固