Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[l10n] Auto-mark strings for translation #677

Merged
merged 11 commits into from
Jul 28, 2021
Merged

[l10n] Auto-mark strings for translation #677

merged 11 commits into from
Jul 28, 2021

Conversation

himdel
Copy link
Collaborator

@himdel himdel commented Jul 21, 2021

Fixes AAH-800

This PR:

  • makes it possible to start marking strings for translation
    • this does not deal with plurals (n_) or non-translating (N_) yet, just the basic version
  • auto-marks as many strings for translation as possible to do automatically (and fixes any errors generated during)

To achieve the first, this adds a simple _ JS string template that either behaves as regular template string, or, when localStorage.test_l10n = true is set (+reload), marks every translatable string in french quotes...

_`Hello ${ 'world' }` #=> 'Hello world'
localStorage.test_l10n = true
_`Hello ${ 'world' }` #=> '>>Hello <<world'

l10n

The latter was just a series of perl invocations to convert anything that looks like a human string,
only strings starting with a capital letter could safely be converted in some cases,
multiline strings and strings with params are not quite possible to do with regex without some major preprocessing.

    perl -i -npe 's/(?<!_)`[A-Z][^`]*`/_$&/' src/**/*.*
    perl -i -npe s/=\''([A-Z][-a-zA-Z0-9_,. ]*)'\'/'={_`$1`}'/g src/**/*.*
    perl -i -npe s/\''([A-Z][-a-zA-Z0-9_,. ]+)'\''(?!:)/_`$1`'/g src/**/*.*
    perl -i -npe s/\''([A-Z][-a-zA-Z0-9_,.:?!@$%\[\]<> ]+)'\''(?!:)/_`$1`'/g src/**/*.*
    perl -i -npe s/=\''([A-Z][-a-zA-Z0-9_,.:?!@$%\[\]<> ]+)'\''/={_`$1`}'/g src/**/*.*
    perl -i -npe 's/"([A-Z][-a-zA-Z0-9_,.:?!@$%\[\]<> '\'']+)"(?!:)/_`$1`/g' src/**/*.*
    perl -i -npe 's/="([A-Z][-a-zA-Z0-9_,.:?!@$%\[\]<> '\'']+)"/={_`$1`}/g' src/**/*.*
    perl -i -npe 's/>([A-Z][-a-zA-Z0-9_,.:?!@$%\[\] '\'']+)</>{_`$1`}</g' src/**/*.*
    perl -i -npe 's/^(\s{4,})([A-Z][-a-zA-Z0-9_,.:?!@$%\[\] '\'']+)(\s*)$/$1\{_`$2`}$3/g unless /,\s*$/' src/**/*.*

(Adding lingui itself in a separate PR, there are still problems with macros and typescript.) (AAH-803)
(Guidelines re pluralization, params coming also separately (AAH-802)

Review: please tell me about any string that's marked incorrectly or shouldn't be marked at all
(If you see a string that should be marked and isn't, just fix it outside of this PR, this should add the bulk of the changes, so we can then finish the rest manually.)

src/api/base.ts Outdated Show resolved Hide resolved
<p>
Use the <Link to={Paths.repositories}>Repository Management</Link>{' '}
Use the{' '}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need more love as a whole :)

<Main>
<section className='body pf-c-content'>
<h2>API token</h2>
<h2>{_`API token`}</h2>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need moore love as a whole :)

@ZitaNemeckova
Copy link
Member

ZitaNemeckova commented Jul 22, 2021

Notes:
`String ${value}` or `String` seems to be skipped.
+ was breaking it.
<br> and <p> were breaking it. (having a space between > and string?)

@himdel himdel force-pushed the l10n branch 3 times, most recently from 4165d0c to 86f7819 Compare July 23, 2021 13:17
@himdel himdel changed the title [WIP] [l10n] Auto-mark strings for translation [l10n] Auto-mark strings for translation Jul 23, 2021
@himdel
Copy link
Collaborator Author

himdel commented Jul 23, 2021

@ZitaNemeckova I've added a commit dealing with `Strings`, fixed some of it in the last commit, and added a small commit the changes any _ => null into () => null, to prevent confusion with gettext.

Might be ready :)

@himdel
Copy link
Collaborator Author

himdel commented Jul 26, 2021

Rebased, ready again :)

Copy link
Member

@ZitaNemeckova ZitaNemeckova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except 3 Enters LGTM 👍

himdel added 9 commits July 28, 2021 11:51
…r<<'

randomly in paths.ts because that's the only place which needs it at runtime (namespaceBreadcrumb)
(and something is putting lodash in window._)

use localStorage.test_l10n to enable marked strings
not *really* needed, but makes it easier to spot l10n if we don't use the underscore for other things
    perl -i -npe 's/(?<!_)`[A-Z][^`]*`/_$&/' src/**/*.*
    perl -i -npe s/=\''([A-Z][-a-zA-Z0-9_,. ]*)'\'/'={_`$1`}'/g src/**/*.*
    perl -i -npe s/\''([A-Z][-a-zA-Z0-9_,. ]+)'\''(?!:)/_`$1`'/g src/**/*.*
    perl -i -npe s/=\''([A-Z][-a-zA-Z0-9_,.:?!@$%\[\]<> ]+)'\''/={_`$1`}'/g src/**/*.*
    perl -i -npe s/\''([A-Z][-a-zA-Z0-9_,.:?!@$%\[\]<> ]+)'\''(?!:)/_`$1`'/g src/**/*.*
    perl -i -npe 's/="([A-Z][-a-zA-Z0-9_,.:?!@$%\[\]<> '\'']+)"/={_`$1`}/g' src/**/*.*
    perl -i -npe 's/"([A-Z][-a-zA-Z0-9_,.:?!@$%\[\]<> '\'']+)"(?!:)/_`$1`/g' src/**/*.*
    perl -i -npe 's/>([A-Z][-a-zA-Z0-9_,.:?!@$%\[\] '\'']+)</>{_`$1`}</g' src/**/*.*
    perl -i -npe 's/^(\s{4,})([A-Z][-a-zA-Z0-9_,.:?!@$%\[\] '\'']+)(\s*)$/$1\{_`$2`}$3/g unless /,\s*$/' src/**/*.*

(with a manual fixup for 1 syntax error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants