Skip to main content
Version: Next

Field variants

Variants solve “one logical field, multiple region/version values”: on export, only the currently selected set remains. Generated code still uses a single field name (e.g. item_id), instead of keeping item_id_zh / item_id_en columns side by side.

Why not split into multiple columns?

Naive approach:

##variditem_iditem_id_zhitem_id_en
##typeintintintint
1100120013001

Problems: every end carries unused columns; code must pick which column to read. After variant export, only one item_id remains.

Declaring in Schema

XML:

<bean name="TestVariant">
<var name="id" type="int"/>
<var name="value" type="int" variants="zh,en,fr"/>
</bean>

__beans__.xlsx: fill the variants column on the field row (e.g. zh,en,fr), following your template.

How to write Excel headers

Add a column per variant: {fieldName}@{variantName}.

Rules:

  1. Variant columns must come after the original field column (value@en to the right of value).
  2. Variant columns do not need their own ##type / ##group; they inherit from the original field.
##varidvaluevalue@zhvalue@en
##typeintint
##groupc,s
1100120013001
210023002

Reading: the original value column is the default/fallback; value@zh and value@en override per variant.

Other data sources

FormatExample
json"value@en": 1001
yamlvalue@en: 1001
lua["value@en"] = 1001
xml<value variant="en">1001</value>

Choosing a variant on export

# Per field: variantKey = {Bean full name}.{field name}
--variant test.TestVariant.value=en

# Global default variant (used by fields not specified individually)
--variant default=zh
SituationBehavior
en is selected and value@en existsUse the variant column
en is selected but value@en is missingFall back to the original field value
variants are defined but CLI has no --variantUse the original field and emit a warning log
Both variant and original field are missingError

You may pass multiple --variant options for different fields.

Choosing vs L10N text tables

ApproachBest for
variantsSame field with multi-region numbers/short copy, fixed at export time
text + text tablekey → multi-language long copy, replaced at runtime or generation time; see Localization

Prefer one primary approach per project to avoid maintaining both in a hard-to-sync way.