Page MenuHomePhabricator

Add character counts for source text and translation
Closed, InvalidPublic

Description

Sometimes it's useful to see how long your translation is compared to the source text just to make sure it's not too long and won't overflow the button/container/wherever it will be placed. From time to time I find myself copy-pasting the source string into the text field just to compare its length with my translation.

Here is a proof-of-concept I made. In order to test it, click on any string in Special:Translate to open up the editor and run the code in the developer console. This will add a small counter in the right side of the textarea which displays the amount of characters in the translation and the source text. The result is also depicted in the attached image below.

var textfield = document.querySelector(".open .tux-textarea-translation"); var sourcetext = document.querySelector(".open .twelve.columns.sourcemessage"); var counter = document.createElement("span"); counter.setAttribute("id", "charcounter"); document.querySelector(".open .tux-editor-editsummary-block .columns").appendChild(counter); counter.textContent = textfield.value.length + " / " + sourcetext.innerText.length; counter.style.fontStyle = "italic"; counter.style.position = "absolute"; counter.style.zIndex = "100"; counter.style.top = "-21px"; counter.style.right = "11px"; counter.style.fontSize = "9pt"; counter.style.color = "darkgrey"; textfield.setAttribute("oninput", "document.querySelector('#charcounter').textContent = document.querySelector('.open .tux-textarea-translation').value.length + ' / ' +  document.querySelector('.open .twelve.columns.sourcemessage').innerText.length");

Note that this is just intended to act as a guide for approximately how long the translation should be - not as a restriction!

Char count.png (596×848 px, 36 KB)

Event Timeline

IMHO, "22 / 194" provides the wrong impression that my translation must have less than 195 characters.

it's not too long and won't overflow the button/container/wherever

@WikiPhoenix: Do you have real examples when a translation has been "too long"? Do you have real examples when a translation has overflown?

I'm asking this because this task proposes a solution but the problem to solve is very unclear to me. If text overflows a button or container, then the button or container or design is broken and needs fixing, not the translation. Also see https://www.w3.org/International/articles/article-text-size.en

IMHO, "22 / 194" provides the wrong impression that my translation must have less than 195 characters.

I stole this idea from the translation platform Crowdin, but I can see now that I have accidentally swapped the numbers:

Crowdin.png (593×300 px, 9 KB)

Do you have real examples when a translation has been "too long"? Do you have real examples when a translation has overflown?

I don't recall this happening for a project on translatewiki, but one notable example is Minecraft: Java Edition (and numerous mods), which I've now been helping out translating for a few years, and whenever new stuff is added to the game's GUI I have to manually check the relevant buttons and sliders to see if the text fits. If it doesn't I have to keep on rewording the translation to make sure it does.

If text overflows a button or container, then the button or container or design is broken and needs fixing, not the translation.

It depends if the developer cares or not. Sadly, translators cannot always rely on the developers to fix these kind of issues.

I'll gladly make a gadget of this if you think it's a better idea.

I don't know if it's a better idea; it's more that I don't believe that the proposal really solves a problem.
If text is displayed in a proportional font, then

iiiiiliiiiiiiiiiiiiiiiiil

with 25 letters may take less horizontal space than

wmmmmmwm

with 8 characters (to use an extreme for better illustration). :)

I get your point but I believe Crowdin's intent was not to give an exact length in pixels, but rather as an estimation. Anyway, you can close this task since I have no clue how to do it myself (or even if users are allowed to close their own tasks) and I can always make a bookmarklet out of this for personal use.

Nikerabbit subscribed.

There are two sides to this discussion

  • Identifying messages that have length limitations
  • How to best convey to translators that they are close or exceeding the limit

In translatewiki.net, we do not have a metadata about messages with length limitations. A few messages may have note of such in the documentation. Because we cannot readily identify these messages, and it's best practice anyway to not have arbitrary limits in the interface, it doesn't make sense to implement the UI in Translate until we can identify those messages.

Marking as invalid, as I am not against the feature itself.

Actually I think the underlying issue is resolved (or at least definitely improved) in T213658: since the original and the translation will now use the same font, if they have approximately the same width in Tux, they will have approximately the same width in real usage as well. Just looking at them doesn’t provide a totally accurate result, but it’s neither what was asked for. (Yes, monospace vs proportional can make a difference, but unlikely to make a such huge one as in @Aklapper’s example above.)

Actually I think the underlying issue is resolved (or at least definitely improved) in T213658: since the original and the translation will now use the same font, if they have approximately the same width in Tux, they will have approximately the same width in real usage as well. Just looking at them doesn’t provide a totally accurate result, but it’s neither what was asked for. (Yes, monospace vs proportional can make a difference, but unlikely to make a such huge one as in @Aklapper’s example above.)

Just noticed the font and I like it. I also agree on that the font change can work as a solution for my issue. Thanks!