Skip to content

Commit

Permalink
ci: add step to get changes in docs translation workflow (#823)
Browse files Browse the repository at this point in the history
* ci: add step to get changes in docs translation workflow

* ci: update get changes step to use HEAD reference

* docs: add more tag to about.md for content separation

* Update docs and translate

* ci: update get changes step in docs translation workflow
docs: add more content separation in about.md

* Update docs and translate

* ci: refine get changes step to filter for docs directory; update about.md more tag

* ci: update get changes step in docs translation workflow; modify more tag in about.md

* ci: update get changes step to save output to changes.txt and display its content

* Update docs and translate

* ci: update get changes step to directly save output to changes.txt; modify more tag in about.md

* ci: update get changes step to include branch context and refine output; modify more tag in about.md

* ci: update docs translation workflow to list all changed markdown files and modify more tag in about.md

* Update docs and translate

* ci: update translation workflow to only translate changed markdown files and adjust more tag in about.md

* Update docs and translate

* ci: update translation workflow to include all markdown files and modify more tag in about.md

* Update docs and translate

* ci: update workflow to improve markdown file handling and enhance naming consistency

* docs: update more tag in about.md for consistency

* Update docs and translate

---------

Co-authored-by: Deeka Wong <[email protected]>
Co-authored-by: huangdijia <[email protected]>
  • Loading branch information
3 people authored Dec 31, 2024
1 parent e27f93e commit 176dd04
Show file tree
Hide file tree
Showing 32 changed files with 95 additions and 58 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/docs-translate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Get All Changed Markdown Files
id: changed-markdown-files
uses: tj-actions/changed-files@v45
with:
# Avoid using single or double quotes for multiline patterns
files: |
**.md
docs/**.md
- name: List All Changed Markdown Files
if: steps.changed-markdown-files.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-markdown-files.outputs.all_changed_files }}
run: |
for file in ${ALL_CHANGED_FILES}; do
echo "$file was changed"
done
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
Expand Down Expand Up @@ -64,6 +82,9 @@ jobs:
php bin/doc-translate
- name: Start Translate EN
if: steps.changed-markdown-files.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-markdown-files.outputs.all_changed_files }}
run: |
pnpm run docs:translate
Expand Down
7 changes: 7 additions & 0 deletions bin/doc-translate.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import OpenAI from "openai";
import { readdir, readFile, writeFile, mkdir } from 'fs/promises';
import path from 'path';
import process from "process";

const endpoint = "https://api.deepseek.com";
const token = process.env["DEEPSEEK_API_KEY"];
const MAX_CONCURRENT = 10; // 最大并发数
const MAX_RETRIES = 3; // 最大重试次数
const ALL_CHANGED_FILES = process.env["ALL_CHANGED_FILES"];

const openai = new OpenAI({
baseURL: endpoint,
Expand Down Expand Up @@ -51,6 +53,11 @@ async function translateFiles(srcDir, destDir) {
for (let i = 0; i < mdFiles.length; i += MAX_CONCURRENT) {
const batch = mdFiles.slice(i, i + MAX_CONCURRENT);
const promises = batch.map(file => {
// 如果指定了 ALL_CHANGED_FILES 环境变量,则只翻译发生变化的文件
if (ALL_CHANGED_FILES && !ALL_CHANGED_FILES.includes(file)) {
console.log(`Skip translation for ${file}`);
return;
}
const srcPath = path.join(srcDir, file);
const destPath = path.join(destDir, file);
return processFile(srcPath, destPath).catch(error => {
Expand Down
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion docs/en/components/amqp-job.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Introduction

`friendsofhyperf/amqp-job` is an asynchronous task component based on the `hyperf/amqp` component, which supports distributing tasks to AMQP services and then consuming them via consumers. It encapsulates the `hyperf/amqp` component, providing a more convenient way to dispatch and consume tasks.
`friendsofhyperf/amqp-job` is an asynchronous task component based on the `hyperf/amqp` component, which supports distributing tasks to the AMQP service and then consuming the tasks through consumers. It encapsulates the `hyperf/amqp` component, providing a more convenient way to distribute and consume tasks.

## Installation

Expand Down
4 changes: 2 additions & 2 deletions docs/en/components/command-signals.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class FooCommand extends HyperfCommand

## Execution

- Manually exit by pressing `Ctrl + C`
- Press `Ctrl + C` to manually exit

```shell
$ hyperf foo
^CReceived signal 2, exiting...
```

- Kill the process using `killall php`
- Use `killall php` to terminate the process

```shell
$ hyperf foo
Expand Down
2 changes: 1 addition & 1 deletion docs/en/components/command-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FooCommand extends HyperfCommand
use ValidatesInput;

/**
* The command line to be executed.
* The command to execute.
*/
protected string $name = 'foo:hello {?name : The name of the person to greet.}';

Expand Down
10 changes: 5 additions & 5 deletions docs/en/components/compoships.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Compoships

**Compoships** provides the ability to specify relationships based on two (or more) columns in the Model ORM of Hyperf. When dealing with third-party or pre-existing schemas/databases, it is common to encounter situations where you need to match multiple columns in the definition of Eloquent relationships.
**Compoships** provides the ability to specify relationships based on two (or more) columns in Hyperf's Model ORM. This is particularly useful when dealing with third-party or pre-existing schemas/databases where it's common to have the need to match multiple columns in the definition of Eloquent relationships.

## The Problem

Eloquent does not support composite keys. Therefore, it is not possible to define a relationship from one model to another by matching multiple columns. Attempting to use a `where` clause (as shown in the example below) does not work when eager loading relationships because **$this->team_id** is null when the relationship is being processed.
Eloquent does not support composite keys. As a result, there is no way to define a relationship from one model to another by matching multiple columns. Attempting to use a `where` clause (as shown in the example below) does not work when eager loading relationships because **$this->team_id** is null when the relationship is being processed.

```php
namespace App;
Expand All @@ -23,7 +23,7 @@ class User extends Model

## Installation

It is recommended to install the **Compoships** component via [Composer](http://getcomposer.org/).
It is recommended to install **Compoships** via [Composer](http://getcomposer.org/).

```shell
composer require friendsofhyperf/compoships
Expand All @@ -37,7 +37,7 @@ Simply have your model class extend the `FriendsOfHyperf\Compoships\Database\Elo

### Using the `FriendsOfHyperf\Compoships\Compoships` Trait

If for some reason you cannot extend your model from `FriendsOfHyperf\Compoships\Database\Eloquent\Model`, you can utilize the `FriendsOfHyperf\Compoships\Compoships` trait. Just use the trait in your model.
If for some reason you cannot extend your model from `FriendsOfHyperf\Compoships\Database\Eloquent\Model`, you can take advantage of the `FriendsOfHyperf\Compoships\Compoships` trait. Just use the trait in your model.

**Note:** To define a multi-column relationship from model *A* to another model *B*, **both models must extend `FriendsOfHyperf\Compoships\Database\Eloquent\Model` or use the `FriendsOfHyperf\Compoships\Compoships` trait**

Expand Down Expand Up @@ -107,7 +107,7 @@ class User extends Model
}
```

The same syntax can define the inverse of the relationship:
The same syntax can be used to define the inverse of the relationship:

```php
namespace App;
Expand Down
2 changes: 1 addition & 1 deletion docs/en/components/config-consul.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Config Consul

A Consul configuration center engine for Hyperf.
A Consul configuration center engine tailored for Hyperf.

## Installation

Expand Down
4 changes: 2 additions & 2 deletions docs/en/components/console-spinner.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Console Spinner

A progress bar component for the Hyperf framework.
A progress bar component provided for the Hyperf framework.

## Installation

Expand Down Expand Up @@ -37,7 +37,7 @@ class FooCommand extends Command
}
```

The `$spinner` is compatible with Symfony's ProgressBar, so you can run any method of this class. Alternatively, you can also use the `withSpinner` method by providing an iterable object.
The `$spinner` is compatible with Symfony ProgressBar, so you can run any method of this class. Alternatively, you can also use the `withSpinner` method by providing an iterable object.

```php
$this->withSpinner(User::all(), function($user) {
Expand Down
4 changes: 2 additions & 2 deletions docs/en/components/fast-paginate.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is a fast `limit`/`offset` pagination macro for Hyperf. It can replace the

This package uses an SQL approach similar to "deferred joins" to achieve this speedup. Deferred joins are a technique where the requested columns are accessed only after applying the `offset` and `limit`.

In our case, we don't actually perform a join but use a `where in` with a subquery. Using this technique, we create a subquery that can be optimized with specific indexes for maximum speed, and then use these results to fetch the full rows.
In our case, we don't actually perform a join but use a `where in` with a subquery. Using this technique, we create a subquery that can be optimized by a specific index for maximum speed, and then use these results to fetch the full rows.

The SQL statement looks like this:

Expand Down Expand Up @@ -41,7 +41,7 @@ No additional steps are required; the service provider will be automatically loa

Anywhere you would use `Model::query()->paginate()`, you can use `Model::query()->fastPaginate()`! It's that simple! The method signature is the same.

Relationships are also supported:
Relations are also supported:

```php
User::first()->posts()->fastPaginate();
Expand Down
2 changes: 1 addition & 1 deletion docs/en/components/http-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ $response = Http::get('https://example.com');

## Documentation

For more information, please refer to the [Laravel HTTP Client Documentation](https://laravel.com/docs/9.x/http-client).
For more information, please refer to the [Laravel HTTP Client documentation](https://laravel.com/docs/9.x/http-client).
2 changes: 1 addition & 1 deletion docs/en/components/http-logger.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Http Logger

An HTTP logging component for Hyperf.
A HTTP logging component for Hyperf.

## Installation

Expand Down
4 changes: 2 additions & 2 deletions docs/en/components/lock.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ if ($lock->get()) {
}
```

The `get` method can also accept a closure. After the closure is executed, the lock will be automatically released:
The `get` method can also accept a closure. The lock will be automatically released after the closure is executed:

```php
lock('foo')->get(function () {
// Lock acquired indefinitely and automatically released...
});
```

If the lock is unavailable when requested, you can control the wait time in seconds. If the lock cannot be acquired within the specified time limit, a `FriendsOfHyperf\Lock\Exception\LockTimeoutException` will be thrown.
If the lock is not available when requested, you can control the number of seconds to wait. If the lock cannot be acquired within the specified time limit, a `FriendsOfHyperf\Lock\Exception\LockTimeoutException` will be thrown:

```php
use FriendsOfHyperf\Lock\Exception\LockTimeoutException;
Expand Down
18 changes: 9 additions & 9 deletions docs/en/components/model-hashids.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Using hashids instead of integer IDs in URLs and list items can be more attractive and clever. For more information, visit [hashids.org](https://hashids.org/).

This package adds hashids to Hyperf models by dynamically encoding/decoding them, rather than persisting them in the database. This eliminates the need for additional database columns and allows for higher performance by using primary keys in queries.
This package adds hashids to Hyperf models by dynamically encoding/decoding them, rather than persisting them in the database. This eliminates the need for an additional database column and allows for better performance by using primary keys in queries.

Features include:

Expand Down Expand Up @@ -42,7 +42,7 @@ Class Item extends Model

### Customizing Hashid Settings

Hashid settings can be customized per model by overriding `getHashidsConnection()`. It must return the name of the connection in `config/autoload/hashids.php`.
You can customize the hashid settings for each model by overriding `getHashidsConnection()`. It must return the name of the connection in `config/autoload/hashids.php`.

## Usage

Expand Down Expand Up @@ -77,7 +77,7 @@ $item->getHashidsConnection();

### Adding Hashid to Serialized Models

Setting it as default:
Set it as default:

```php

Expand All @@ -98,13 +98,13 @@ class Item extends Model

```

Setting it for a specific route:
Set it for a specific route:

`return $item->append('hashid')->toJson();`

### Implicit Route Binding

If you want to resolve implicit route bindings using the model's hashid value, you can use `HashidRouting` in the model.
If you want to resolve implicit route bindings using the model's hashid value, you can use `HashidRouting` in your model.

```php

Expand All @@ -121,7 +121,7 @@ class Item extends Model

It overrides `getRouteKeyName()`, `getRouteKey()`, and `resolveRouteBindingQuery()` to use hashids as the route key.

It supports Laravel's custom specific route key functionality.
It supports Laravel's custom specific route key feature.

```php

Expand All @@ -133,7 +133,7 @@ Route::get('/items/{item:slug}', function (Item $item) {

#### Customizing the Default Route Key Name

If you want to resolve implicit route bindings using another field by default, you can override `getRouteKeyName()` to return the field name during resolution and `getRouteKey()` to return its value in links.
If you want to resolve implicit route bindings using another field by default, you can override `getRouteKeyName()` to return the field name used in the resolution process and `getRouteKey()` to return its value in links.

```php

Expand All @@ -158,7 +158,7 @@ class Item extends Model

```

You can still specify hashid for specific routes.
You can still specify the hashid for specific routes.

```php

Expand All @@ -170,7 +170,7 @@ Route::get('/items/{item:hashid}', function (Item $item) {

#### Supporting Other Laravel Implicit Route Binding Features

When using `HashidRouting`, you can still use soft deletion and child route bindings.
When using `HashidRouting`, you can still use soft deletes and child route bindings.

```php

Expand Down
2 changes: 1 addition & 1 deletion docs/en/components/model-morph-addon.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Model Morph Addon

The Model Morph Addon supports polymorphic associations in Hyperf models.
The Model Morph Addon supports polymorphic relationships in Hyperf models.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion docs/en/components/model-observer.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Model Observer

The Model Observer component, designed for the Hyperf framework.
The Model Observer component is designed for the Hyperf framework.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion docs/en/components/notification-easysms.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class TestNotification extends Notification implements Smsable
];
}

// or return customer Message
// or return custom Message
// public function toSms(mixed $notifiable): array|Message
// {
// return new Message();
Expand Down
4 changes: 2 additions & 2 deletions docs/en/components/notification-mail.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ composer require friendsofhyperf/notification-mail:~3.1.0

## Usage

### Use `Notifiable` Trait in Model
### Use `Notifiable` trait in Model

```php
<?php
Expand Down Expand Up @@ -51,7 +51,7 @@ class User extends Model
php bin/hyperf.php gen:markdown-mail Test
```

Output:
output

```php

Expand Down
7 changes: 4 additions & 3 deletions docs/en/components/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ composer require friendsofhyperf/notification:~3.1.0

## Usage

### Using `Notifiable` Trait in Model
### Using the `Notifiable` Trait in a Model

```php
<?php
Expand All @@ -18,7 +18,8 @@ declare(strict_types=1);
namespace App\Model;

use Hyperf\DbConnection\Model\Model;
use FriendsOfHyperf\Notification\Traits\Notifiable;use Overtrue\EasySms\PhoneNumber;
use FriendsOfHyperf\Notification\Traits\Notifiable;
use Overtrue\EasySms\PhoneNumber;

/**
* @property int $id
Expand Down Expand Up @@ -237,7 +238,7 @@ return [

```

#### Using in Controller
#### Using in a Controller

```php
$user = User::create();
Expand Down
2 changes: 1 addition & 1 deletion docs/en/components/purifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ To use your own settings, publish the configuration.
php bin/hyperf.php vendor:publish friendsofhyperf/purifier
```

The configuration file `config/autoload/purifier.php` will look like this:
The configuration file `config/autoload/purifier.php` is as follows:

```php

Expand Down
6 changes: 3 additions & 3 deletions docs/en/components/redis-subscriber.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

A Redis native protocol subscriber based on Swoole coroutines, forked from [mix-php/redis-subscriber](https://github.com/mix-php/redis-subscriber).

This Redis subscription library, built on Swoole coroutines, connects directly to the Redis server using sockets without relying on the phpredis extension. The subscriber offers the following advantages:
This Redis subscription library, based on Swoole coroutines, connects directly to the Redis server using sockets, without relying on the phpredis extension. The subscriber offers the following advantages:

- **Smooth Modifications**: You can add or cancel subscription channels at any time, enabling seamless channel switching.
- **Cross-Coroutine Safe Shutdown**: The subscription can be closed at any moment safely.
- **Channel Message Retrieval**: The library's encapsulation style is inspired by the [go-redis](https://github.com/go-redis/redis) library in Golang, allowing you to retrieve subscribed messages through channels.
- **Cross-Coroutine Safe Shutdown**: The subscription can be closed at any moment.
- **Channel Message Retrieval**: The library's encapsulation style is inspired by the [go-redis](https://github.com/go-redis/redis) library in Golang, retrieving subscription messages through channels.

## Installation

Expand Down
Loading

0 comments on commit 176dd04

Please sign in to comment.