antenna/行内翻译

laravel的行内翻译包,包含blade和vue插件

0.11.1 2024-02-16 09:49 UTC

README

Screenshot of inline translation tool

此包允许您管理翻译,并实际上在行内翻译您的Laravel应用程序。

我们建议您不要在生产环境中使用此包。翻译可以在预发布或开发环境中管理,并通过自定义实现(或通过您的git仓库)同步到生产环境。

安装

将包作为项目依赖项添加

composer require antenna/inline-translations

您必须运行以下命令以发布配置。这将添加 config/inline-translations.php 文件,您可以在其中配置包。同时还会发布一个Vue组件(resources/assets/vendor/v-inline-translations/app.js)。您可以将此作为Vue插件用于您的Vue实例。如果您在Vue组件中使用翻译,则需要此组件。

php artisan vendor:publish --tag=inline-translations

(可选) 使用Vue插件。 methodName 参数定义了您在Vue组件中使用的翻译函数。当翻译模式激活时,此函数将被包覆盖

import VInlineTranslations from "resources/assets/vendor/v-inline-translations/app";
Vue.use(VInlineTranslations, {methodName: '__t'});
new Vue({
  ...
});

不要忘记在已部署的配置中配置您的支持语言(见下方)。默认配置为支持单一语言(英语)。

配置

此包有一些配置选项。所有配置参数都有默认值,因此此包应该直接可用。下面您将找到默认配置以及所有可用参数的解释

return [
    'routes' => [
        /**
         * All paths of this package will be prefixed with the value defined in this parameter.
         * By default following paths can be used to activate or disable the tool:
         *   - /{prefix}/enable
         *   - /{prefix}/disable
         */
        'prefix'     => 'inline-translations',

        /**
         * Underneath you can define middleware that will be added to all routes of this package.
         * It might be sensible to add some kind of authentication in this middleware.
         */
        'middleware' => null,
    ],

    /**
     * The location where your translations are found, is defined in this parameter.
     * Laravel by default stores this in resources/lang
     */
    'translation_folder' => 'resources/lang',

    /**
     * This parameter defines the width of the widget when it is opened. This can be changed depending
     * on the amount of languages you are supporting, in order to get a better overview.
     */
    'widget_width' => 350,

    /**
     * Here you can define on which environments, translations are possible.
     * When the active environment is not in the array underneath, the tool will not be available.
     */
    'translation_environments' => ['local', 'staging'],
];

技术

哪些内容可以行内翻译?

此包自带以下翻译管理功能

  • Blade(默认)
  • Vue

我们希望在将来添加其他实现

使用方法

我们不仅试图简化翻译的技术功能,还简化了翻译的工作流程和管理。

这是通过一个可折叠的行内“小部件”完成的。如果打开,它将可视化每个配置在应用程序中的语言可以在页面上找到的键和(已定义的)翻译。

为了使用行内翻译工具,您应访问 /inline-translations/enable,这将启用工具。在您的工具中浏览时,您将能够通过我们的界面进行翻译。可以配置一个按钮来启用/禁用工具(如果需要)。

要关闭工具,请访问 /inline-translations/disable

待办事项

我们希望在将来添加一些功能