Define Variables in Your Dynamic Phrases

Condense similar phrases into one phrase using the Localize dashboard.

The Dynamic Phrases feature makes it easy to identify phrases that contain dynamic content (such as dates, names, email addresses, etc.) so they can be merged into a single phrase for translation - right from within the Localize dashboard!

As a result, you don't have to ask your developers to add tags in your HTML, and your translators only have to translate the phrase one time - saving you time and money!


Bonus: Set it and forget it!

After you've defined variable(s) in a dynamic phrase, any new phrases that are found that match the pattern in that phrase will be ignored, and won't be brought in as a new phrase!

View the tutorial video, or follow the instructions below to define variables in your dynamic phrases.

Dynamic Phrase Manager

The Dynamic Phrase Manager allows you to see all of the dynamic phrases in your project.

  • ย Click the trash can to delete the phrase.
  • ย Click the edit icon to make changes to the dynamic phrase.
  • ย Click View to see the phrase in your dashboard.

You can also search for a dynamic phrase using the search bar.

Identify dynamic phrases

The first step is to identify phrases in your project that contain mostly the same content but with perhaps 1 or 2 pieces of dynamic data.

While looking through new phrases in your Pending bin, look for patterns.

Once you've identified a group of similar phrases, click on the Define variables link below the phrase.

1. Define variables

The first step is to define your variables.

a. Highlight the dynamic content

Follow the on-screen instructions to highlight the dynamic content in the phrase.

b. Name the variable

Next, give the variable a name in the Pending variables panel.


Use Unique Variable Names

If you are creating more than 1 variable in a single phrase, you must give the variables unique names. Otherwise, there may be problems when placing the variables in the translation.

c. Advanced Options

It is highly recommended for you to select any of the Advanced Options that are available so that you may better specify the type of variable you are defining. This will also help in clearly defining the variable part of the phrase so you don't capture other similar phrases that should not be captured.

d. Select Criteria

Select the appropriate criteria from the list:

  • Custom Regex (see details below)
  • Alphabetical Only
  • Numerical Only
  • Alphanumeric Only

e. Select Character Limit Qualifier

If you selected anything other than Custom Regex in the previous step, you'll need to set the character limit qualifier from one of the following:

  • Is at least
  • Is at most
  • Is exactly

f. Enter the Character Limit

Next, enter the specific limit for the number of characters.

g. Click Save

Your new variable is saved, and the dynamic content in your phrase is replaced with the variable name.

h. Repeat for other dynamic content

You can repeat the process for other dynamic content in your phrase as needed.
Once done, click the Continue button.

2. Review matching phrases

a. Review phrases

Matching phrases will be displayed, allowing you to see which phrases will be merged into one phrase.


All Bins are Searched

Localize will search for matching phrases in all of your phrase bins. So while you may have spotted 4 in your Pending bin, there may be others in your Published or Deprecated bins.

Localize will find all of them, and merge them all into one phrase.

b. Click I Understand

When ready, click the I Understand button.

c. Click Continue

Next, click the Continue button.

3. Confirm changes

Review the changes that will be made.

When you click the Confirm Changes button, your phrases will be merged into one new phrase. and you'll be returned to the Published phrases bin.


Phrases will be deleted

You should verify that you want the phrases to be merged, since the merging process completely deletes the duplicate phrases from your Project.


Translations will be deleted

When the phrases are merged, ALL translations will be deleted for the phrases, even for the phrase that remains with the variable in it.
If you need to, first save the translation somewhere outside of the Localize dashboard.

After adding a variable to a phrase and adding a new translation that encompasses the variable, you'll clearly see the variable in the source phrase when you click on the variable in the translation. This will help your translators to better identify the variables in your phrases.


Example Use Cases: Advanced Options

  • 1st or last word in the phrase
    • Using the Advanced Options is especially useful when your variable is the first or last word in the phrase.
    • In these cases you will want to specify the type and/or the length of the variable that you want to replace in the phrase.
    • This will ensure that only the appropriate phrases will match the criteria.

In the following video, we use the Advanced Options to limit the variable to "Numerical Only" with at most 2 digits.


Easily Find Phrases with Variables

When a variable is defined in a phrase, Localize will add the lz-dynamic-phrase system label to the phrase, making it very easy to find all phrases with variables by using the labels filter.

Custom Regex

When using the Advanced Options you can select Custom Regex as your Criteria, and then you can enter your own custom Regular Expression (regex) (note the exceptions below). This gives you incredible flexibility for defining exactly what you don't want to translate in any particular phrase.

For examples of custom Regular Expressions that you might want to use, and for more instructions, see the Regular Expressions doc in our Developer Docs.

NOTE 1: You should NOT include the ^ symbol to denote the "start of a phrase", and you shouldn't use the $ to denote the "end of the phrase". These are added for you automatically, and if you include them then your regex will fail.

NOTE 2: You cannot add a capture group by using parenthesis, due to the nature of how the regex is built behind-the-scenes.


Example Use Case: Advanced Options: Regex: Percentages

Creating a variable for a percentage value:

  • If your phrase is similar to this:
    • "2.75% discount"
    • "1.82% discount"
  1. Select the numerical part of the phrase without the percent sign (e.g. 2.75, 1.82)
  2. Name the variable: discount-amount
  3. Select Advanced Options
  4. Add the custom regex: \d{1,2}.\d{2}
  5. Continue on to save your new phrase.
  • This results in the phrase: {{discount-amount}}% discount

In the following video, we define 3 variables using Regular Expressions by selecting the Custom Regex option in the Advanced section.