Page MenuHomePhabricator

Add character counts for source text and translation
Open, Needs TriagePublic

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!

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptTue, Sep 10, 10:32 PM

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:

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.