naimkhalifa/laravel-google-cloud-translation 问题修复 & 功能扩展

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

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

naimkhalifa/laravel-google-cloud-translation

最新稳定版本:0.3.1

Composer 安装命令:

composer require naimkhalifa/laravel-google-cloud-translation

包简介

A package to easily integrate Google Cloud Translation API with Laravel

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require naimkhalifa/laravel-google-cloud-translation

You can publish the config file with:

php artisan vendor:publish --provider="NaimKhalifa\GoogleCloudTranslation\GoogleCloudTranslationServiceProvider"

This is the contents of the published config file:

return [

    /*
    |--------------------------------------------------------------------------
    | Google Cloud Translation API Key
    |--------------------------------------------------------------------------
    |
    | Your Google Cloud Translation API Key.
    | You can get it from https://console.cloud.google.com/apis/credentials
    | More info at https://cloud.google.com/translate/docs/setup
    |
    */
    'api_key' => env('GOOGLE_CLOUD_TRANSLATION_API_KEY'),

    /*
    |--------------------------------------------------------------------------
    | Default Source Language
    |--------------------------------------------------------------------------
    |
    | The default source language to translate from.
    | You can find the list of supported languages here:
    | https://cloud.google.com/translate/docs/languages
    |
    */
    'default_source_language' => 'en',

    /*
    |--------------------------------------------------------------------------
    | Default Target Language
    |--------------------------------------------------------------------------
    |
    | The default target language to translate to.
    | Obviously, it must be different from the default source language.
    |
    */
    'default_target_language' => 'es',

    /*
    |--------------------------------------------------------------------------
    | Default Format
    |--------------------------------------------------------------------------
    |
    | The default format to translate to.
    | Acceptable values are html or text.
    |
    */
    'default_format' => 'text',
];

Usage

GoogleCloudTranslation::translate(string $text, array $options)

Use this method if you want to translate a single text string.

# This would translate using default_source_language 
# and default_target_language config values
GoogleCloudTranslation::translate('Hello World');

# with options
GoogleCloudTranslation::translate('Hello World', [
  'source' => 'en',
  'target' => 'fr',
  'format' => 'text', # or 'html'
]);

GoogleCloudTranslation::translateBatch(array $input, array $options)

Use this method if you want to translate multiple strings at once.

GoogleCloudTranslation::translateBatch([
  'Something else',
  'Another string to translate',
  'And a third one because we can'
])

# You can also pass options to this method
GoogleCloudTranslation::translateBatch('Hello World', [
  'source' => 'en',
  'target' => 'fr',
  'format' => 'text', # or 'html'
]);

Commands

Translate language files

This Artisan command allows you to translate strings in a language file using Google Cloud Translation.
The format of the file you want to translate should conform to what you would typically find under Laravel /lang folder.

php artisan google-cloud-translation:translate-lang-file [options]

Options

--source: Specify the source language for translation. (Required)
--target: Specify the target language for translation. (Required)
--file: Specify the path to the language file you want to translate. (Required)
--dryrun: Enable dry run mode, which will display translations without saving them to a file. (Optional, enabled by default)

Example

php artisan google-cloud-translation:translate-lang-file --source=en --target=fr --file=resources/lang/en/messages.php

This is when you're running the command with --dryrun option enabled (by default).
This command will translate all the strings in the messages.php language file from English (en) to French (fr) and display the translations on the terminal.
You then have to confirm with prompt for the translations to be saved to destination file (in this example, that would be resources/lang/fr/messages.php).

Be careful that this will override any existing file that lives at that path! Basically replacing it.

If you want to bypass confirmation and directly write to destination, you can disable dryrun mode (--dryrun=false)

php artisan google-cloud-translation:translate-lang-file --source=en --target=fr --file=resources/lang/en/messages.php --dryrun=false

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固