Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 117 additions & 2 deletions src/content/docs/crowdin/online-editor/supported-placeholders.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,66 @@ description: Learn about the placeholder formats Crowdin recognizes and highligh
slug: supported-placeholders
---

import { Aside } from '@astrojs/starlight/components';

Placeholders (also known as variables, interpolations, or format specifiers) are special tokens in source strings that are replaced with dynamic content (like names, numbers, or dates) when the application runs. It's crucial that these placeholders are not translated and that their syntax remains correct in the translated strings.

Crowdin automatically recognizes and highlights common placeholder formats in the [Editor](/online-editor/). This helps translators easily identify non-translatable text and prevents accidental modification. The [Variables mismatch QA check](/project-settings/qa-checks/#qa-check-parameters) uses these recognized formats to ensure consistency between source and translation.

## Placeholder Examples
## Real-World Example

Here's how placeholders work in practice:

**Source string:**
```
Welcome, %{name}! You have {count} new messages.
```

**In the Editor:**
- `%{name}` and `{count}` are highlighted as placeholders
- Translators know not to modify these tokens

**Translated string (Spanish):**
```
¡Bienvenido, %{name}! Tienes {count} mensajes nuevos.
```

The placeholders remain unchanged, ensuring your application can properly insert the user's name and message count.

## Quick Reference

Use this table to quickly identify which format category your placeholders belong to:

Crowdin recognizes a wide variety of placeholder formats commonly used in different programming languages, frameworks, and localization standards. Below are examples grouped by common styles. Note that some placeholder syntaxes might overlap or be used across multiple languages or frameworks.
| Format | Example | Common Use Cases |
|--------|---------|------------------|
| **Printf-style** | `%s`, `%d`, `%1$s` | C, PHP, Python, Java, Android XML |
| **ICU / Brace style** | `{0}`, `{name}`, `{0:C2}` | .NET, Java, JavaScript (i18n) |
| **PHP variables** | `$variable`, `$array['key']` | PHP templates |
| **Ruby/Rails** | `%{name}`, `#{variable}` | Ruby on Rails i18n |
| **Twig** | `{{ variable }}`, `{% trans %}` | Symfony, Drupal |
| **Freemarker** | `${variable}`, `<#if>` | Java templates |
| **Custom** | `__placeholder__`, `%variable%` | Various frameworks |

## Detailed Placeholder Formats

Crowdin recognizes a wide variety of placeholder formats commonly used in different programming languages, frameworks, and localization standards. Below are examples grouped by common styles.

<Aside type="tip">
Looking for a specific format? Use your browser's search (Ctrl+F or Cmd+F) to quickly find examples.
</Aside>

### Printf-style (C, PHP, Python, Java, Objective-C, etc.)

**When to use:** C-based languages, Android XML strings, iOS `.strings` files, Python with `%` formatting, PHP `sprintf`.

These formats typically start with `%` and can include flags, width, precision, and type specifiers.

**Example in context:**
```
String in code: "User %s rated your post %d/5 stars"
In the Editor: "El usuario %s calificó tu publicación %d/5 estrellas"
```

**Common Type Specifiers:**

```
Expand Down Expand Up @@ -107,8 +155,16 @@ These formats typically start with `%` and can include flags, width, precision,

### ICU MessageFormat / .NET / Java Style

**When to use:** .NET applications, Java MessageFormat, JavaScript i18n libraries, React Intl.

These formats typically use curly braces (`{ }`).

**Example in context:**
```
String in code: "Hello {name}, your balance is {amount, number, currency}"
In the Editor: "Hola {name}, tu saldo es {amount, number, currency}"
```

**Indexed Arguments:**

```
Expand Down Expand Up @@ -170,8 +226,16 @@ These formats typically use curly braces (`{ }`).

### PHP Style

**When to use:** PHP templates, Laravel Blade (for variables).

Includes standard variables and object/array access.

**Example in context:**
```
String in template: "Welcome back, $user->name!"
In the Editor: "Bienvenido de nuevo, $user->name!"
```

```
$variable
$object->property
Expand All @@ -187,15 +251,31 @@ $TAG_START$, $TAG_END$ // Often used for markup/tags

### Python Style

**When to use:** Python with `.format()` method or f-strings (represented after parsing).

Besides Printf-style and ICU-style, includes `.format()` style.

**Example in context:**
```python
# In Python code: "Hello {name}, you have {count} items".format(name=user, count=5)
# In the Editor: "Hola {name}, tienes {count} elementos"
```

```
{0}, {1} // Indexed
{name} // Named
```

### Ruby / Rails Style

**When to use:** Ruby on Rails i18n, Ruby ERB templates.

**Example in context:**
```ruby
# In Rails i18n: t('greeting', name: @user.name) => "Hello %{name}"
# In the Editor: "Hola %{name}"
```

```
%{name}
#{variable}
Expand All @@ -205,8 +285,16 @@ $_ // Special variable (also used in PHP)

### Twig Style

**When to use:** Symfony framework, Drupal CMS, Craft CMS.

Includes variables, filters, functions, and control structure tags.

**Example in context:**
```twig
{# In Twig template: "Welcome {{ user.name }}" #}
{# In the Editor: "Bienvenido {{ user.name }}" #}
```

**Variable Output:**

```
Expand Down Expand Up @@ -239,8 +327,16 @@ Includes variables, filters, functions, and control structure tags.

### Freemarker Style

**When to use:** Apache Freemarker templates (Java-based).

Uses `${...}` for variable output and `<#...>` or `</#...>` for directives.

**Example in context:**
```ftl
<!-- In template: "Hello ${user.firstName}" -->
<!-- In the Editor: "Hola ${user.firstName}" -->
```

**Variable Output:**

```
Expand All @@ -264,8 +360,16 @@ ${value}$ // Value within syntax

### Miscellaneous / Other Formats

**When to use:** Various proprietary or legacy systems, custom frameworks.

Various other formats recognized by Crowdin.

**Example in context:**
```
String: "Click __button_name__ to continue"
In the Editor: "Haz clic en __button_name__ para continuar"
```

```
&_var_& // Ampersand underscore
*|Object.Property|* // Pipe symbols
Expand All @@ -278,3 +382,14 @@ $(variable) // Dollar parentheses
%%variable%% // Double percent signs
%variable% // Single percent signs (may overlap with Printf, used in Twig/other)
```

## Need Custom Placeholders?

<Aside type="note">
If your project uses placeholder formats not included in this list, you can define custom placeholder patterns using regular expressions in your project's QA settings. This ensures they are correctly recognized, highlighted, and validated by the Variables mismatch QA check.
</Aside>

## Related Resources

- [QA Checks](/project-settings/qa-checks/) - Learn how to configure validation rules for placeholders
- [Online Editor](/online-editor/) - See how placeholders are highlighted during translation
114 changes: 112 additions & 2 deletions src/content/docs/enterprise/online-editor/supported-placeholders.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,60 @@ Placeholders (also known as variables, interpolations, or format specifiers) are

Crowdin Enterprise automatically recognizes and highlights common placeholder formats in the [Editor](/enterprise/online-editor/). This helps translators easily identify non-translatable text and prevents accidental modification. The [Variables QA check](/enterprise/project-settings/qa-checks/#qa-check-parameters) uses these recognized formats to ensure consistency between source and translation.

## Placeholder Examples
## Real-World Example

Crowdin Enterprise recognizes a wide variety of placeholder formats commonly used in different programming languages, frameworks, and localization standards. Below are examples grouped by common styles. Note that some placeholder syntaxes might overlap or be used across multiple languages or frameworks.
Here's how placeholders work in practice:

**Source string:**
```
Welcome, %{name}! You have {count} new messages.
```

**In the Editor:**
- `%{name}` and `{count}` are highlighted as placeholders
- Translators know not to modify these tokens

**Translated string (Spanish):**
```
¡Bienvenido, %{name}! Tienes {count} mensajes nuevos.
```

The placeholders remain unchanged, ensuring your application can properly insert the user's name and message count.

## Quick Reference

Use this table to quickly identify which format category your placeholders belong to:

| Format | Example | Common Use Cases |
|--------|---------|------------------|
| **Printf-style** | `%s`, `%d`, `%1$s` | C, PHP, Python, Java, Android XML |
| **ICU / Brace style** | `{0}`, `{name}`, `{0:C2}` | .NET, Java, JavaScript (i18n) |
| **PHP variables** | `$variable`, `$array['key']` | PHP templates |
| **Ruby/Rails** | `%{name}`, `#{variable}` | Ruby on Rails i18n |
| **Twig** | `{{ variable }}`, `{% trans %}` | Symfony, Drupal |
| **Freemarker** | `${variable}`, `<#if>` | Java templates |
| **Custom** | `__placeholder__`, `%variable%` | Various frameworks |

## Detailed Placeholder Formats

Crowdin Enterprise recognizes a wide variety of placeholder formats commonly used in different programming languages, frameworks, and localization standards. Below are examples grouped by common styles.

<Aside type="tip">
Looking for a specific format? Use your browser's search (Ctrl+F or Cmd+F) to quickly find examples.
</Aside>

### Printf-style (C, PHP, Python, Java, Objective-C, etc.)

**When to use:** C-based languages, Android XML strings, iOS `.strings` files, Python with `%` formatting, PHP `sprintf`.

These formats typically start with `%` and can include flags, width, precision, and type specifiers.

**Example in context:**
```
String in code: "User %s rated your post %d/5 stars"
In the Editor: "El usuario %s calificó tu publicación %d/5 estrellas"
```

**Common Type Specifiers:**

```
Expand Down Expand Up @@ -109,8 +155,16 @@ These formats typically start with `%` and can include flags, width, precision,

### ICU MessageFormat / .NET / Java Style

**When to use:** .NET applications, Java MessageFormat, JavaScript i18n libraries, React Intl.

These formats typically use curly braces (`{ }`).

**Example in context:**
```
String in code: "Hello {name}, your balance is {amount, number, currency}"
In the Editor: "Hola {name}, tu saldo es {amount, number, currency}"
```

**Indexed Arguments:**

```
Expand Down Expand Up @@ -172,8 +226,16 @@ These formats typically use curly braces (`{ }`).

### PHP Style

**When to use:** PHP templates, Laravel Blade (for variables).

Includes standard variables and object/array access.

**Example in context:**
```
String in template: "Welcome back, $user->name!"
In the Editor: "Bienvenido de nuevo, $user->name!"
```

```
$variable
$object->property
Expand All @@ -189,15 +251,31 @@ $TAG_START$, $TAG_END$ // Often used for markup/tags

### Python Style

**When to use:** Python with `.format()` method or f-strings (represented after parsing).

Besides Printf-style and ICU-style, includes `.format()` style.

**Example in context:**
```python
# In Python code: "Hello {name}, you have {count} items".format(name=user, count=5)
# In the Editor: "Hola {name}, tienes {count} elementos"
```

```
{0}, {1} // Indexed
{name} // Named
```

### Ruby / Rails Style

**When to use:** Ruby on Rails i18n, Ruby ERB templates.

**Example in context:**
```ruby
# In Rails i18n: t('greeting', name: @user.name) => "Hello %{name}"
# In the Editor: "Hola %{name}"
```

```
%{name}
#{variable}
Expand All @@ -207,8 +285,16 @@ $_ // Special variable (also used in PHP)

### Twig Style

**When to use:** Symfony framework, Drupal CMS, Craft CMS.

Includes variables, filters, functions, and control structure tags.

**Example in context:**
```twig
{# In Twig template: "Welcome {{ user.name }}" #}
{# In the Editor: "Bienvenido {{ user.name }}" #}
```

**Variable Output:**

```
Expand Down Expand Up @@ -241,8 +327,16 @@ Includes variables, filters, functions, and control structure tags.

### Freemarker Style

**When to use:** Apache Freemarker templates (Java-based).

Uses `${...}` for variable output and `<#...>` or `</#...>` for directives.

**Example in context:**
```ftl
<!-- In template: "Hello ${user.firstName}" -->
<!-- In the Editor: "Hola ${user.firstName}" -->
```

**Variable Output:**

```
Expand All @@ -266,8 +360,16 @@ ${value}$ // Value within syntax

### Miscellaneous / Other Formats

**When to use:** Various proprietary or legacy systems, custom frameworks.

Various other formats recognized by Crowdin Enterprise.

**Example in context:**
```
String: "Click __button_name__ to continue"
In the Editor: "Haz clic en __button_name__ para continuar"
```

```
&_var_& // Ampersand underscore
*|Object.Property|* // Pipe symbols
Expand All @@ -281,6 +383,14 @@ $(variable) // Dollar parentheses
%variable% // Single percent signs (may overlap with Printf, used in Twig/other)
```

## Need Custom Placeholders?

<Aside>
If your project uses placeholder formats not included in this list, you can define [Custom Placeholders](/enterprise/custom-placeholders/) in your Organization Settings to ensure they are correctly recognized and handled.
</Aside>

## Related Resources

- [QA Checks](/enterprise/project-settings/qa-checks/) - Learn how to configure validation rules for placeholders
- [Custom Placeholders](/enterprise/custom-placeholders/) - Define organization-wide custom placeholder patterns
- [Online Editor](/enterprise/online-editor/) - See how placeholders are highlighted during translation