Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Help Needed for sheet Translations

September 11 (1 year ago)

Edited September 11 (1 year ago)
GiGs
Pro
Sheet Author
API Scripter

I'm thinking about what posts I need for translations in my guide.

Some of the wiki page on translations is inscrutable to me, so I have a few questions:

1. New sheets

First, the translation page refers to DEV (where it says, "It is especially important that the text stays there while the sheet-i18n code is only on Dev, otherwise your sheet will no longer work on the main site until sheet-i18n makes it to main"), but Dev has been shut down. What do you do with new sheets and new translations? How long does it take a translation to be visible? Do you need to do anything special when creating new translations?

2. Attribute values (not HTML attributes)

I understand how to create translations for basic text, titles, placeholders, etc, but if you have an attribute like @{strength}, what do you need to do to make the strength part translateable?

3. Variable Replacement

This seems to be telling you how to create text that will not be translated, but I don't follow this at all. What's a use case for this, and how do you use it in that case?

Is the {0} just part of the text to be translated (or not translated), or is it important somehow?

4. Dynamic key Replacement

What is this for? It seems to give examples using two languages, but the while point of translations is you don't need to speciafy how many languages are affected-  that's just handled through crowdin.

5. getTranslationByKey

How and when do you use this?

6. List Ordering

What? I have no idea what's going on here, is there another explanation for it, or an example on the repo?


I think I can do basic translations, but all my sheets have been for my local group so I havent had to look at it. Does anyone have any answers to the above sections? I've numbered them so you can answer the bits you know about and state which part you are answering.

September 11 (1 year ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

The translation wiki instructions are probably one of the most confusing sections of the wiki. I think it's because it was written by sheet authors that were figuring it out as they went, and a lot of the more advanced features of the i18n setup just didn't have a lot of use cases in early sheets because we didn't have the tech to make use of them until later on. So, here's my personal outline of translating sheets:

Sheet Dev

Personally, I never put the default text in the content of the element regardless of if its a new sheet or adding translations to an existing sheet. This is because there is no possible display error where the default content gets displayed unless Roll20 completely removes the i18n setup, in which case we probably have bigger issues than some text not displaying.

Translating Attribute Names

There is no way to translate attribute names. Macro calls will always be in whatever the initial language of the sheet is.

Variable Replacement

Of the confusing topic of advanced translation properties, variable replacement is probably one of the least well explained on the wiki. This is likely because there are very few real use cases for it in the context of sheets (especially before we got custom roll parsing; more on that later). The simplest, although not necessarily the most real world, use case I can think of is translating ordinals (e.g. 1st, 2nd, etc). You could just have the translators translate the whole thing, but then you're relying on them to do the format you want it in. For instance, maybe the person translating the sheet into spanish decides to use segundo instead of 2er. This then makes the gender of various items not match in the spanish language version of the sheet whereas 2er wouldn't have cared about gender. Another solution would be to use two separate spans. One for the number and one for the ordinal abbreviation:

<span class="ordinal-container">
  <span>1</span>
  <span data-i18n="1-ordinal">st</span>
</span>

The problem here is what if a language changes the order of the number and the ordinal, or the spacing between the two, or even adds something before and after the number for an ordinal? I'm not saying these actually exist, but these are the sort of issues that i18n variables help with. They allow us to have untranslated text as well as translated text in the same element. For our ordinal example, this would look like:

<span data-i18n="{{0}}ordinal" data-i18n-vars="1"></span>

Then our (english) translation file for this would look like:

{
  "{{0}}ordinal":"{{0}}st"
}

The translation system then sees that {{0}} and uses it as an index to look up the correct untranslated item in the element's data-i18n-vars list. Note that this uses zero-indexing just like javascript arrays, and each individual untranslated item is separated by a bar (|).

Dynamic Key Replacement

This i18n feature is for when we need to translate a value of an attribute so that the displayed value is different from what the actual attribute value is. In the Dragonbane sheet that released recently, we used this for displaying the abbreviations of the selected attribute for each item in the secondary-skills repeating section. This then allowed us to have html like this:

<div class="expanded">
  <select name="attr_attribute_translation">
    <option data-i18n="strength-abbreviation" value="strength-abbreviation"></option>
    <option data-i18n="dexterity-abbreviation" value="dexterity-abbreviation"></option>
</div>
<div class="collapsed">
  <span data-i18n-dynamic name="attr_attribute_translation"></span>
</div>

This then lets our expanded mode (or edit mode) use a select so the player can set which ability score to base the secondary skills rolls off of, but when in collapsed (or view) mode, we just show a span that will simply display the translation of the value.

List Ordering

Ironically, I'm going to break the order here to keep the purely html i18n stuff together. List ordering allows us to have a list of things (like say skills) ordered alphabetically (or whatever order we need it in) for each language.

The way this works is to specify the list key on the container. Then add a list-item key to each child of the element (or grandchild depending on how your nesting works). The list-item key will be one of the items in the comma separated list that will be the translation value of the list key on the container. And then finally, we add the list key to the translation.json:

{
  "skills-list":"acrobatics,athletics,brawling,lockpicking,flight"
}

Then a translator can reorder those list keys to be in the order that the translated versions are in their language. Of particular note here is that the individual keys in the list are never themselves translated, only the order of them is changed. For instance, the spanish version of this list order would be:

{
  "skills-list":"acrobatics,athletics,lockpicking,brawling,flight"
}

Note that the individual words are still in English, but that lockpicking and brawling have changed places (forzar cerraduras and peleando respectively).

getTranslationByKey

This function is actually extremely useful when doing any sort of complex sheet. Before custom roll parsing it was mostly used for dynamically created macro strings. This wasn't ideal as it would then not necessarily be translated into the language of the user that actually sent the roll. With custom roll parsing, we can now dynamically translate roll query prompts as people roll. I use this extensively in the two storypath sheets (Scion 2e and They Came From ...). Which results in roll queries like this:


All the text in that roll query is translated to my language on the fly by the sheet using getTranslationByKey.

With some added code, you can even use this to translate variable strings such that you can translate something like this:


In this example the numbers are untranslated (and dynamically created based on the stats of the sheet and even options the user made in previous roll queries). Academics and Intellect are translated values, but aren't directly in the translation value of the translation key for this string. The rest of the sentence is translated, and then the attribute values injected using regex replacements looking for the various variable indexes in the translation string. Here's what that translation entry looks like in the translation.json:

{
  "Roll {{skill}} and {{attribute}} with {{enhancement number}} enhancements and {{addDice}} additional dice?": "Roll {{0}} and {{1}} with {{2}} enhancements and {{3}} additional dice?",
}

Note that the key doesn't use the indexes, it uses descriptions of what that index represents in the string. This is because the replacement, whether done by bespoke javascript using regex replacement or the i18n module's -vars handling, looks at the translated value of the key for the index replacement, not the key itself.

This last example is obviously pretty complex and might not be needed by the majority of sheet authors, but shows how much you can do with CRP and getTranslationByKey.

September 11 (1 year ago)
GiGs
Pro
Sheet Author
API Scripter

Thank you Scott, that's very helpful. I'm a bit to sleepy to grasp specific details right npow, but I can tell you have cleared a lot up.

Scott C. said:

The translation wiki instructions are probably one of the most confusing sections of the wiki.

I used to say the Custom Roll Parsing page was most confusing, but I think I have to update that now!
September 11 (1 year ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

One thing I should note is that putting the default value in the content of the element does help with generating your initial translation.json using something like Andreas' automated tool. But other than that, there's no reason to use it. And I use the K-scaffold in all my projects, and it builds the translation file for me.

September 11 (1 year ago)
GiGs
Pro
Sheet Author
API Scripter

Andreas's automating tool seems to me that it's most useful for sheets built without translation and you don't want to go through the ordeal of adding it all afterwards.

If you're using a templating tool, there's no reason to ever use it.

September 11 (1 year ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

yep agreed.