Direct Text Replacement - The Simplest Parameter Type
The simple parameter type is the most straightforward parameter type in string.fit. It performs direct text replacement using the @{paramName} syntax, with no formatting, no transformation, and no language-specific rules.
Content: "Hello, @{name}!"
ICU Equivalent: "Hello, {name}!"
Params:
{
"paramName": "name",
"type": "simple"
}
Expected Output:
"Zhang San" → "Hello, Zhang San!"The simple parameter is the default type when no type is specified. If you omit the type field, string.fit treats the parameter as simple.
The JSON definition for a simple parameter is minimal:
{
"paramName": "name",
"type": "simple"
}
Since simple is the default type, you can also write:
{
"paramName": "name"
}
| Parameter Type | Use Case | Example |
|---|---|---|
| simple | Direct text replacement, no formatting | User names, item names, static text |
| number | Numbers with formatting (currency, decimals) | Price with currency formatting |
| date | Date formatting with locale support | Created date with locale-aware format |
| plural | Plural forms (zero/one/few/many/other) | Item count with plural rules |
| select | Non-numeric conditional text | Gender-specific pronouns |
Use simple parameters when you need to insert pre-formatted values that already come from your application logic. Don't use simple parameters if you need the parameter to be formatted by string.fit - use the appropriate type instead.
In the content string, simple parameters use the @{paramName} syntax:
{
"content": "Welcome, @{username}! Your order #@{orderId} is ready."
}
When rendered with { username: "Li Ming", orderId: 12345 }, the output becomes:
"Welcome, Li Ming! Your order #12345 is ready."
The simple parameter performs these steps:
@{paramName} in the content stringThe value is inserted exactly as provided. If the value is already formatted by your application (e.g., a localized date string), it will be inserted as-is without additional processing.
Simple parameters in generated code are the most straightforward - they just return the value directly:
function formatSimple(value: string): string {
return value;
}
static func formatSimple(_ value: String) -> String {
return value
}
Python does not have a separate format_simple function because simple parameters return the value directly in format_with_params without any transformation.
private static String formatSimple(String value) {
return value;
}
The simple parameter type is the most basic type - it simply returns the value as-is. No formatting, no conversion, no special handling. The value is inserted directly into the template.
All other parameter types wrap simple parameters internally. When rendering complex types, the final text output for each branch is produced by a simple parameter mechanism:
{
"content": "You have @{count} @{itemCount}",
"params": [
{
"paramName": "count",
"type": "simple"
},
{
"paramName": "itemCount",
"type": "plural",
"options": { "type": "cardinal" },
"list": [
{ "value": "one", "text": "item" },
{ "value": "other", "text": "items" }
]
}
]
}
In this plural parameter, each text field (like "item") is inserted based on the plural rule that matches the count value. The simple count parameter provides the raw number.
{
"content": "@{genderText}",
"params": [
{
"paramName": "genderText",
"type": "select",
"options": { "type": "gender" },
"list": [
{ "value": "male", "text": "He is online" },
{ "value": "female", "text": "She is online" },
{ "value": "other", "text": "They are online" }
]
}
]
}
Each selected text ("He is online", etc.) is rendered via the simple parameter mechanism - no transformation, just direct string insertion.
When your application already handles formatting (e.g.,你已经本地化的日期字符串, 已格式化的货币), use simple parameters to insert them without re-formatting:
{
"content": "Order placed on @{orderDate} for amount @{orderAmount}",
"params": [
{ "paramName": "orderDate", "type": "simple" },
{ "paramName": "orderAmount", "type": "simple" }
]
}
Since simple is the default type, you can omit the type field to keep your parameter definitions clean:
{
"paramName": "username"
}
If you need locale-aware date formatting, proper number formatting, or grammatical plural forms, use the appropriate parameter type instead of simple:
{ "paramName": "amount", "type": "number", "options": { "style": "currency", "currency": "USD" } }
{ "paramName": "createdAt", "type": "date", "options": { "format": "yyyy-MM-dd", "zoneId": "UTC" } }
{ "paramName": "count", "type": "plural", "options": { "type": "cardinal" }, "list": [...] }
If you need numbers to be formatted (e.g., currency, percentage), don't use simple. Pass pre-formatted strings or use the number type:
❌ Bad: "Price: @{price}" → "Price: 1234.56"
✅ Good: "Price: @{price}" with { "paramName": "price", "type": "number", "options": { "style": "currency", "currency": "USD" } }
{
"strings": [
{
"key": "greeting",
"translations": {
"en-US": {
"content": "Hello, @{name}! Welcome to @{appName}.",
"params": [
{ "paramName": "name" },
{ "paramName": "appName" }
]
},
"zh-CN": {
"content": "你好,@{name}!欢迎来到@{appName}。",
"params": [
{ "paramName": "name" },
{ "paramName": "appName" }
]
},
"ja-JP": {
"content": "こんにちは、@{name}!@{appName}へようこそ。",
"params": [
{ "paramName": "name" },
{ "paramName": "appName" }
]
}
}
}
]
}