A variant is an attribute of a string that allows you to save two or more different translations for strings that have the same source text. Variants are required to differentiate strings with the same source text but with different contextual meaning, e.g. "home" a house, and "home" a homepage on a website (link to module). To summarize, the same source text with different variants are considered two strings in Smartling.
Variants can be set to an arbitrary value for some file types, and for others is set automatically based on the string’s key. The variant of a string is displayed in the Smartling dashboard in the Strings View, under the source string.
How Smartling Creates Variants
HTML
Take the HTML file, sample.html, below as an example:
<html>
<head></head>
<body>
<div>Here is some text to translate</div>
<div>Here is some text to translate</div>
<div>Here is some text to translate</div>
</body>
</html>
In the above example, the variant is not set to anything (i.e., is null). This is the default behavior for HTML content, but other file types behave differently (see How Your Content Is Broken Into Strings).
In our sample.html example, the variant is set by adding a variant attribute to the DIV tags, as shown below:
<html>
<head></head>
<body>
<div variant="string1">Here is some text to translate</div>
<div variant="string2">Here is some text to translate</div>
<div variant="string3">Here is some text to translate</div>
</body>
</html>
For more information, continue reading to Global Delivery Network Projects.
Excel
If we place the same text into three cells of an Excel file, three separate strings would have appeared in Smartling. This is because the Excel parsing process automatically assigns a different variant attribute to each string extracted from the file. Meaning, all strings are ingested uniquely in Business Documents.
CSV
Although a similar file format to the above, CSV is processed very differently to Excel. The same text in three cells of a CSV is deduplicated and appears as one string in Smartling. Meaning, no variants are created by default. This behavior can always be controlled with the use of directives.
Other Examples
For other file types, such as Java Properties, the key in the source file is automatically copied as the variant attribute. Continue reading to Resource Files for more information.
Global Delivery Network Projects
The Global Delivery Network analyzes every HTML request and captures strings based on HTML block tags. If content within the block tags (such as an in-line tag) changes, Smartling creates a new unique string, even if the text itself is identical to another unique string.
Example 1:
HTMLString 1: p>Please contact us to find out more.</p>
String 2: <p>Please <a href="contact.html">contact us</a> to find out more.</p>
These are parsed by the GDN as two unique strings, even though the text is identical because there are different inline tags within the blocks.
To manually create variants, you can use a variant HTML attribute within a block tag to enclose the string you want to make a variant and assign it a numeric or text value. The HTML5 compliant version of this attribute is data-sl-variant.
Example 2:
HTMLString 1: <div>Same text, captured twice with variant metadata.</div>
String 2: <div variant="Variant1">Same text, captured twice with variant metadata.</div>
String 2 (HTML5): <div data-sl-variant="Variant1">Same text, captured twice with variant metadata.</div>
Smartling parses these as two unique strings, even though the content within the block tags is identical. String 1 has no variant metadata, String 2 has the variant metadata Variant1.
Resource Files
How Smartling creates variants from Application Resource Files depends on the file type and the parsing instructions included in the file. Most application resource files use key/value pairs, where the ‘value’ is the string and the ‘key’ is a label. For some file types, Smartling may capture keys as metadata for a string and create Variants if two different keys have the same value. See below for detailed information on each file type:
Key-value based files: Java Properties, iOS/Mac OS .strings
Every string is created with variant metadata, which is the key. If the ‘keys’ are different for two strings with the same ‘value’ then Smartling will create two strings using the key as context metadata.
Javastring1= Home
string2= Home
YAML
Every string is created with variant metadata. The variant metadata is the full path of keys leading to the translatable string.
YAML
Strings:string1: Home
string2: Home
Android Resources
Every string is created with variant metadata which is the value of the string.name attribute. So if the value of a string is the same for two strings but the string.name attribute is different Smartling creates two strings.
XML
<string name="string1">Home</string>
<string name="string2">Home</string>
RESX-RESW
Every string is created with variant metadata which is the value of the data.name attribute. If the value of a string is the same for two strings but the data.name attribute is different, Smartling creates two strings.
XML
<data name="string1">
<value>Home</value>
</data><data name="string2">
<value>Home</value>
</data>
Gettext POT
The msgid value is captured as the key but is not used to create variants.
The string is captured with variant metadata if msgctxt is present for the string. The value of the msgctxt key will be used as variant metadata.
#:0001
msgctxt "string1"
msgid "Home"
msgstr ""#0002
msgctxt "string2"
msgid "Home"
msgstr ""
JSON
Strings are created with variant metadata only if you have configured the JSON file to use keys and have turned on the variants behavior. Then the Smartling key for a string is used as the variant metadata for that string. For accounts created after June 11th 2015, JSON strings are created with variant metadata by default, with the full path of keys leading to a string being captured as the variant.
For some files uploaded before June 2015, an older parser version applies and variants must be enabled through file directives.
JSON
{
"string1": "Home",
"string2": "Home"
}
XML
Strings are created with variant metadata only if you have configured the XML file to use keys and have turned on the variants behavior. Then the Smartling key for a string is used as the variant metadata for that string.
XML<?xml version="1.0" encoding="utf-8"?>
<!-- smartling.translate_paths = data/item/string -->
<!-- smartling.source_key_paths = data/item/{string.name} -->
<!-- smartling.variants_enabled = true -->
<data>
<item>
<string name="name1">Home</string> </item>
<item>
<string name="name2">Home</string>
</item>
</data>
Adding Variant Metadata After Translation has Begun
You can always modify source content by updating the source file and re-uploading to Smartling under the same file name.
Please note, if you capture content without variant metadata, begin translation and, later, add variant metadata (for example: by adding variant tags to your HTML or re-uploading the same file with variants enabled), all strings with variant metadata will be considered new and unique.
Configuring SmartMatch can help you avoid having to retranslate these strings, but they will be counted as new strings and add to your account's Words Under Management.
Using SmartMatch with Variants
You can set up SmartMatch to match variants of strings in your Translation Memory. Enabling 100% match with variants will only match strings with identical text when the variant metadata is the same. Enabling 100% match without variants will ignore variant metadata and match any strings with identical text.
Viewing Variants in Smartling
The value of a string’s variant attribute is displayed in the Strings View of the Smartling dashboard, as shown in the screenshots below;
You can also use the Key/Variant Filter to find a string with variants and take bulk action. See Actions in Strings View for more.
Variant displayed in CAT Tool
In the Smartling CAT Tool, the value of a string’s variant attribute is displayed in the Additional Details panel (top right);