-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
251 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# 字段变体(Variants) | ||
|
||
有时候同一个字段可能有多个配置。一个非常常见的场景是制作本地化数据时,不同地区的某个初始道具有不同的值。 | ||
|
||
一个粗糙的做法类似这样: | ||
|
||
|##var|id|item_id|item_id_zh|item_id_en| | ||
|-|-|-|-|-| | ||
|##type|int|int|int|int| | ||
||1|1001|2001|3001| | ||
||2|1002|2002|3002| | ||
|
||
虽然这样确实可以工作,但有几个问题: | ||
|
||
- 对于某个地区(如zh)来说,它并不需要其他地区的item_id,这个会增大了配置数据,也增加了无谓的内存开销 | ||
- 程序员需要根据当前地区,选择从 item_id_zh 还是 item_id_en读取数据,这带来不便 | ||
|
||
字段变体较好地解决了此问题。无论是哪个地区的item_id_{xxx},最终都会导出为一个公共的item_id字段,并且不包含其他用不到item_id_{yyy}。 | ||
|
||
## 定义 | ||
|
||
当前只有字段支持变体,所有可以定义字段的地方都可以定义变体信息。 | ||
|
||
### xml定义 | ||
|
||
```xml | ||
<bean name="TestVariant"> | ||
<var name="id" type="int"/> | ||
<var name="value" type="int" variants="zh,en,fr,jp"/> | ||
</bean> | ||
``` | ||
|
||
### 在 \_\_beans\_\_.xlsx中定义 | ||
|
||
![variant_beans](/img/variant_beans.jpg) | ||
|
||
### 在数据表的标题行定义 | ||
|
||
对于需要定义变体的字段,为每个变体定义一个`{fieldName}@{variant}`的变量。有几个规则: | ||
|
||
- 变体标题头所在的列必须在变量名列之后,即 `value@en`必须在`value`列之后 | ||
- 不需要为变体变量定义`type`及`group`之类信息,变体变量直接使用原始变量相应的值,即`value@en`的`type`会取`value`的`type`。 | ||
|
||
![variant_table_header](/img/variant_table_header.jpg) | ||
|
||
|
||
## 配置变体数据 | ||
|
||
### excel格式族 | ||
|
||
|
||
![variant_table_header](/img/variant_table_header.jpg) | ||
|
||
### json格式 | ||
|
||
```json | ||
{ | ||
"id":1, | ||
"value@en": 1001 | ||
} | ||
|
||
``` | ||
|
||
### xml格式 | ||
|
||
```xml | ||
<data> | ||
<id>1</id> | ||
<value variant="en">1001</value> | ||
</data> | ||
``` | ||
|
||
### yaml格式 | ||
|
||
```yml | ||
id: 1 | ||
value@en: 1001 | ||
``` | ||
### lua格式 | ||
```lua | ||
return { | ||
id=1, | ||
["value@en"] = 1001, | ||
} | ||
``` | ||
|
||
## 导出数据 | ||
|
||
一般来说,既然定义了变量变体,导出数据时应该为该变量指定当前应该使用的变体。命令参数`--variant {variantKey}={variantName}`用于为字段指定当前使用的变体。 | ||
|
||
`{variantKey}`为`{beanFullName}.{fieldName}`, `{variantName}`为变体名。 例如`--variant TestVariant.value=en`表示导出数据时value字段取`value_en`列对应的值。 | ||
|
||
在为某个变量指定了当前使用的变体后,如果对应的字段不存在,则取默认字段的值。同样地,以变体en为例,如果`value_en`列不存在,则取`value`列的值,如果`value`列也不存在,则抛出字段找不到的错误。 | ||
|
||
如果某个字段定义了变体,但没有在命令行中使用`--variant`指定该字段使用的变体名,则读取不含变量的原始变量的值。此时Luban会打印一行警告日志。 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
i18n/en/docusaurus-plugin-content-docs/current/manual/variants.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Field Variants | ||
|
||
Sometimes the same field may have multiple configurations. A very common scenario is that when making localized data, different regions have different values for a certain initial path. | ||
|
||
A rough approach is like this: | ||
|
||
|##var|id|item_id|item_id_zh|item_id_en| | ||
|-|-|-|-|-| | ||
|##type|int|int|int|int| | ||
||1|1001|2001|3001| | ||
||2|1002|2002|3002| | ||
|
||
Although this does work, there are several problems: | ||
|
||
- For a certain region (such as zh), it does not need item_id in other regions, which will increase the configuration data and increase unnecessary memory overhead | ||
|
||
- The programmer needs to choose to read data from item_id_zh or item_id_en according to the current region, which is inconvenient | ||
|
||
Field variants solve this problem better. Regardless of the region, item_id_{xxx} will eventually be exported as a common item_id field, and will not include other unused item_id_{yyy}. | ||
|
||
## Definition | ||
|
||
Currently, only fields support variants. Variant information can be defined in all places where fields can be defined. | ||
|
||
### XML definition | ||
|
||
```xml | ||
<bean name="TestVariant"> | ||
<var name="id" type="int"/> | ||
<var name="value" type="int" variants="zh,en,fr,jp"/> | ||
</bean> | ||
``` | ||
|
||
### Define in \_\_beans\_\_.xlsx | ||
|
||
![variant_beans](/img/variant_beans.jpg) | ||
|
||
### Define in the header row of the data table | ||
|
||
For fields that need to define variants, define a variable of `{fieldName}@{variant}` for each variant. There are several rules: | ||
|
||
- The column where the variant header is located must be after the variable name column, that is, `value@en` must be after the `value` column | ||
|
||
- There is no need to define information such as `type` and `group` for variant variables. Variant variables directly use the corresponding values of the original variables, that is, the `type` of `value@en` will take the `type` of `value`. | ||
|
||
![variant_table_header](/img/variant_table_header.jpg) | ||
|
||
## Configure variant data | ||
|
||
### excel format family | ||
|
||
![variant_table_header](/img/variant_table_header.jpg) | ||
|
||
### json format | ||
|
||
```json | ||
{ | ||
"id":1, | ||
"value@en": 1001 | ||
} | ||
|
||
``` | ||
|
||
### xml format | ||
|
||
```xml | ||
<data> | ||
<id>1</id> | ||
<value variant="en">1001</value> | ||
</data> | ||
``` | ||
|
||
### yaml format | ||
|
||
```yml | ||
id: 1 | ||
value@en: 1001 | ||
``` | ||
### lua format | ||
```lua | ||
return { | ||
id=1, | ||
["value@en"] = 1001, | ||
} | ||
``` | ||
|
||
## Exporting data | ||
|
||
Generally speaking, since a variable variant is defined, the variant that should be used should be specified for the variable when exporting data. The command parameter `--variant {variantKey}={variantName}` is used to specify the currently used variant for the field. | ||
|
||
`{variantKey}` is `{beanFullName}.{fieldName}`, `{variantName}` is the variant name. For example, `--variant TestVariant.value=en` means that when exporting data, the value field takes the value corresponding to the `value_en` column. | ||
|
||
After specifying the currently used variant for a variable, if the corresponding field does not exist, the value of the default field is taken. Similarly, taking variant en as an example, if the `value_en` column does not exist, the value of the `value` column is taken. If the `value` column does not exist either, an error that the field cannot be found is thrown. | ||
|
||
If a field has a variant defined, but the variant name used by the field is not specified using `--variant` in the command line, the value of the original variable without the variant is read. At this time, Luban will print a warning log. |
Oops, something went wrong.