Custom localization variable placeholders

Respresso lets you define custom variable placeholders for any output format. In this case, a placeholder means any string that will be replaced with a variable's value within your app at runtime.

Currently, Respresso resolves variable placeholders in the following order:

  1. Single format overrides for that variable when the converter uses that format key. (Each converter has a specific list of keys that specifies the resolution order within this step.)
  2. Global format overrides. (Works the same as the previous)
  3. Printf format converted to the platform-specific version if the format supports it.
  4. Skips variable placeholder change. (Respresso's variable format will be used: {{ var_name }})

Single variable placeholder overrides

You can define format key specific placeholder overrides in the variable settings. This lets you define a placeholder template for single or multiple formats.

This method is primarily to add support for custom formatting options specific to a single variable. If you are looking for a format wide change, see the global variable overrides section.

Follow the steps below to define a custom placeholder for a single variable:

  1. Open the editor panel by clicking the localization's key.
  2. Click on the variable edit icon to open the variable editor dialog.
  3. Select a format key from the dropdown in the last row of the Manual format section.
  4. Type your variable placeholder template in the last row, next to the selected format key.
  5. Click the + button to add your variable placeholder template.
  6. Click the OK button to apply your changes.
How to add single variable placeholder template

Removing a template is similar, just press the trash button next to the template and click the OK button to apply your changes. (Bottom center part of the figure above.)

You can also add custom format key if you use a custom Flow configuration by typing it in the dropdown's search field and pressing the + button next to it. (Bottom left part of the figure above.)

Global variable placeholder overrides

Global variable placeholders works in a similar way as single ones. The only difference that they have lower priority, but they don't have to be set for each variable. This is the proper way to set up a different variable placeholder template for an output format.

Follow the steps below to define a custom placeholder for a format key globally:

  1. Make sure that you have no unsaved changes. (Save or discard them before editing the config.)
  2. Open the config editor dialog by clicking the Config button next to the language management toolbar.
  3. Add a format key as a field to the variables.overrides object by typing it to the input field and clicking the + button next to it.
  4. Change the newly added field's value to your desired placeholder template by typing it into the corresponding input.
  5. Save your config changes. (This will immediately execute a full save process like the regular Save button.)
How to add a global variable placeholder template

Currently, the config editor contains only these overrides, but it may contain other configuration options in the future. Make sure that you edit the variables.overrides.<format key>'s value to be the desired template as a string.

Placeholder template options

Each custom placeholder you define - whether it is single or global - acts like a template. Respresso will replace some predefined keys with an actual, context aware value.

Currently, you can use the following placeholders:

  • {{key}}: Variable's key (name).
  • {{index}}: Variable's 0 based argument index. (Extracted from the variable's format or computed from the order.)
  • {{position}}: Same as {{index}} but 1 based. Basically index + 1 that is equivalent with the format's argument index.

Please note that only exact matches are replaced.
No whitespace is allowed within these keys and currently there is no way to escape these.

Format keys

Whether you define exact or global placeholders, you have to tie it to a specific output format key.

By default, Respresso uses the following format keys:

  • android
  • ios
  • web
  • json

Default resolution order by output format:

  • Android strings xml: android
  • Apple iOS strings: ios
  • JSON: json, web

(Other output formats does not contain variables, so they are not listed.)

Common variable placeholder templates

Desired formatPlaceholder template
{ variable_name }{ {{key}} }
{ variable_name, fn }{ {{key}}, fn }
{ 0 }{ {{index}} }
{ 0, fn }{ {{index}}, fn }
{ 1 }{ {{position}} }
{ 1, fn }{ {{position}}, fn }

(Replace fn with your custom formatting function's name.)