Page MenuHomeWildfire Games

l10n JS cleanup
ClosedPublic

Authored by elexis on Apr 28 2017, 3:57 PM.

Details

Summary

The function in l10n.js creates one or two variable for each translate* call when it can just check for the cache variable directly or return a copy of the string in the cache object directly.
Some of these variables are only used for read access once in the line following that, so pointless and not making it easier to read either.
The comment to use these functions as a performance improvement to Engine.Translate* is duplicated once per function, when having it once on the top of the file is sufficient (even if someone solely looks at the JSdoc).
While already changing almost all lines, use the capital letter for globals in accordance with the coding conventions.
Some calls are simplified a lot.
While at it, use let for the three remaining vars.

Test Plan

That every of the functions is still working as expected can be tested by opening the tech tree, scrolling through civs and hovering some icons,
especially one that has a projectile limit tooltip like the fortress.
Open the gamesetup to the other functions still being called correctly.
Add a warn("functionName"); to the top of each function (and to both cases of translateObjectKeys) to see that indeed each of these functions is called.
That the translate* functions still return a copy of the string can be verified the following way:

var x = translate("Linear Splash Damage");
x = "nope";
warn(translate("Linear Splash Damage"));

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

elexis created this revision.Apr 28 2017, 3:57 PM
Vulcan added a subscriber: Vulcan.Apr 28 2017, 4:41 PM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/903/ for more details.

leper requested changes to this revision.Apr 28 2017, 8:31 PM
leper added a subscriber: leper.
leper added inline comments.
binaries/data/mods/mod/globalscripts/l10n.js
13 ↗(On Diff #1508)

This is a behaviour change, since now " " returns false, while it previously returned true. (Might not be an issue, but at least translating "" isn't really possible and might lead to strange results (caused by the po format).)

I guess this could use && variable.trim() or && !!variable.trim() if we really want that original behaviour.

17 ↗(On Diff #1508)

English

28 ↗(On Diff #1508)

English

43 ↗(On Diff #1508)

English

58 ↗(On Diff #1508)

Well, what have we got here :P

Also s/ / /.

This revision now requires changes to proceed.Apr 28 2017, 8:31 PM
elexis updated this revision to Diff 1523.Apr 29 2017, 4:18 AM
elexis edited edge metadata.
elexis marked 4 inline comments as done.

Remove isNonEmptyString altogether and capitalize language names, even if it's an adjective, because grammar. Fix whitespace.

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/916/ for more details.

leper added inline comments.Apr 29 2017, 6:34 PM
binaries/data/mods/mod/globalscripts/l10n.js
149 ↗(On Diff #1523)

This now allows calling translate(""), which might result in something unexpected.

elexis marked an inline comment as done.Apr 30 2017, 1:01 AM
elexis added inline comments.
binaries/data/mods/mod/globalscripts/l10n.js
13 ↗(On Diff #1508)

Renaming isNonEmptyStringto isTranslatableString for clarification, as it fits more to the context and is less prone to naming conflicts.

Returning an actual boolean as that will be expected from this global.

17 ↗(On Diff #1508)

Apparently so

Languages and nationalities are always capitalised, both when used as nouns and when used as adjectives.

http://esl.fis.edu/grammar/rules/capital.htm

149 ↗(On Diff #1523)

Agree.

Calling translate("")in this version is an issue because it would now save the property to that object whereas before it wouldn't be set.

The result of translate("") isn't be cached because of the foo[bar] existence checks , so tinygettext shows the "Could not translate:" logwarning each call (independent of this proposal).

However since translating a (nonemptyish) string to an empty string isn't possible either, it consistent and not worthwhile to go for the uglier check for a function call that shouldn't exist to begin with.

elexis updated this revision to Diff 1545.Apr 30 2017, 1:03 AM
elexis marked an inline comment as done.

See above + fix some duplicate spaces

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/930/ for more details.

leper accepted this revision.May 1 2017, 1:59 AM

Thanks.

This revision is now accepted and ready to land.May 1 2017, 1:59 AM
This revision was automatically updated to reflect the committed changes.