threads / patch / 57265

patch, 2 partsMore similar messages refactoring

Subject: [PATCH 0/2] More similar messages refactoring

## tl;dr

8 messages between Jan 19, 2022 and Feb 11, 2022. Diffs are folded; open one to read it.

replies: 7people: 5as markdown or json

Bagas Sanjaya· Jan 19, 2022, 09:44 UTC · lore

We came across the need to refactor message strings when we did l10n work. So let's continue the factorization work done in [1].

[1]: https://lore.kernel.org/git/pull.1088.v5.git.1641412944.gitgitgadget@gmail.com/

Bagas Sanjaya (2):
  sequencer: factor GIT_AUTHOR_* from message strings
  advice: refactor "action is not possible because you have unmerged
    files"
 advice.c    | 10 +++++-----
 sequencer.c | 12 ++++++------
 2 files changed, 11 insertions(+), 11 deletions(-)
base-commit: df3c41adeb212432c53d93ce6ace5d5374dc6e11
-- 
An old man doll... just what I always wanted! - Clara
Bagas Sanjaya· Jan 19, 2022, 09:44 UTC · re: Bagas Sanjaya · lore

[PATCH 1/2] sequencer: factor GIT_AUTHOR_* from message strings

Factor messages containing GIT_AUTHOR_* variable.
Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
---
 sequencer.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Show changes to sequencer.c +6 −6
diff --git a/sequencer.c b/sequencer.c
index 6abd72160c..472feb053c 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -848,17 +848,17 @@ int read_author_script(const char *path, char **name, char **email, char **date,
 	for (i = 0; i < kv.nr; i++) {
 		if (!strcmp(kv.items[i].string, "GIT_AUTHOR_NAME")) {
 			if (name_i != -2)
-				name_i = error(_("'GIT_AUTHOR_NAME' already given"));
+				name_i = error(_("'%s' already given"), "GIT_AUTHOR_NAME");
 			else
 				name_i = i;
 		} else if (!strcmp(kv.items[i].string, "GIT_AUTHOR_EMAIL")) {
 			if (email_i != -2)
-				email_i = error(_("'GIT_AUTHOR_EMAIL' already given"));
+				email_i = error(_("'%s' already given"), "GIT_AUTHOR_EMAIL");
 			else
 				email_i = i;
 		} else if (!strcmp(kv.items[i].string, "GIT_AUTHOR_DATE")) {
 			if (date_i != -2)
-				date_i = error(_("'GIT_AUTHOR_DATE' already given"));
+				date_i = error(_("'%s' already given"), "GIT_AUTHOR_DATE");
 			else
 				date_i = i;
 		} else {
@@ -867,11 +867,11 @@ int read_author_script(const char *path, char **name, char **email, char **date,
 		}
 	}
 	if (name_i == -2)
-		error(_("missing 'GIT_AUTHOR_NAME'"));
+		error(_("missing '%s'"), "GIT_AUTHOR_NAME");
 	if (email_i == -2)
-		error(_("missing 'GIT_AUTHOR_EMAIL'"));
+		error(_("missing '%s'"), "GIT_AUTHOR_EMAIL");
 	if (date_i == -2)
-		error(_("missing 'GIT_AUTHOR_DATE'"));
+		error(_("missing '%s'"), "GIT_AUTHOR_DATE");
 	if (date_i < 0 || email_i < 0 || date_i < 0 || err)
 		goto finish;
 	*name = kv.items[name_i].util;
-- 
An old man doll... just what I always wanted! - Clara
Jean-Noël AVILA· Feb 11, 2022, 20:26 UTC · re: Bagas Sanjaya · lore

Re: [PATCH 1/2] sequencer: factor GIT_AUTHOR_* from message strings

Hi,
Note that this patch is still relevant from an i18n point of view.
If  you do not wish to propose it, I'll cherry-pick it for my next series.
Best regards,
Jean-Noël
Bagas Sanjaya· Jan 19, 2022, 09:44 UTC · re: Bagas Sanjaya · lore

[PATCH 2/2] advice: refactor "action is not possible because you have unmerged files"

Factor action names (cherry-picking, committing, merging, pulling, and reverting) out of the message string.

Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
---
 advice.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Show changes to advice.c +5 −5
diff --git a/advice.c b/advice.c
index 1dfc91d176..4c72856478 100644
--- a/advice.c
+++ b/advice.c
@@ -175,15 +175,15 @@ void list_config_advices(struct string_list *list, const char *prefix)
 int error_resolve_conflict(const char *me)
 {
 	if (!strcmp(me, "cherry-pick"))
-		error(_("Cherry-picking is not possible because you have unmerged files."));
+		error(_("%s is not possible because you have unmerged files."), "Cherry-picking");
 	else if (!strcmp(me, "commit"))
-		error(_("Committing is not possible because you have unmerged files."));
+		error(_("%s is not possible because you have unmerged files."), "Commiting");
 	else if (!strcmp(me, "merge"))
-		error(_("Merging is not possible because you have unmerged files."));
+		error(_("%s is not possible because you have unmerged files."), "Merging");
 	else if (!strcmp(me, "pull"))
-		error(_("Pulling is not possible because you have unmerged files."));
+		error(_("%s is not possible because you have unmerged files."), "Pulling");
 	else if (!strcmp(me, "revert"))
-		error(_("Reverting is not possible because you have unmerged files."));
+		error(_("%s is not possible because you have unmerged files."), "Reverting");
 	else
 		error(_("It is not possible to %s because you have unmerged files."),
 			me);
-- 
An old man doll... just what I always wanted! - Clara
René Scharfe· Jan 19, 2022, 11:11 UTC · re: Bagas Sanjaya · lore

Re: [PATCH 2/2] advice: refactor "action is not possible because you have unmerged files"

Am 19.01.22 um 10:44 schrieb Bagas Sanjaya:
Show 33 quoted lines
> Factor action names (cherry-picking, committing, merging, pulling, and
> reverting) out of the message string.
>
> Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
> ---
>  advice.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/advice.c b/advice.c
> index 1dfc91d176..4c72856478 100644
> --- a/advice.c
> +++ b/advice.c
> @@ -175,15 +175,15 @@ void list_config_advices(struct string_list *list, const char *prefix)
>  int error_resolve_conflict(const char *me)
>  {
>  	if (!strcmp(me, "cherry-pick"))
> -		error(_("Cherry-picking is not possible because you have unmerged files."));
> +		error(_("%s is not possible because you have unmerged files."), "Cherry-picking");
>  	else if (!strcmp(me, "commit"))
> -		error(_("Committing is not possible because you have unmerged files."));
> +		error(_("%s is not possible because you have unmerged files."), "Commiting");
>  	else if (!strcmp(me, "merge"))
> -		error(_("Merging is not possible because you have unmerged files."));
> +		error(_("%s is not possible because you have unmerged files."), "Merging");
>  	else if (!strcmp(me, "pull"))
> -		error(_("Pulling is not possible because you have unmerged files."));
> +		error(_("%s is not possible because you have unmerged files."), "Pulling");
>  	else if (!strcmp(me, "revert"))
> -		error(_("Reverting is not possible because you have unmerged files."));
> +		error(_("%s is not possible because you have unmerged files."), "Reverting");
>  	else
>  		error(_("It is not possible to %s because you have unmerged files."),
>  			me);

That effectively reverts 8785c42532 (i18n: advice: internationalize message for conflicts, 2016-06-17). Why? Having the capitalized English present participle of the action appear somewhere in a translated string would sure look quite foreign in some (most?) languages.

René
Ævar Arnfjörð Bjarmason· Jan 19, 2022, 15:31 UTC · re: Bagas Sanjaya · lore

Re: [PATCH 2/2] advice: refactor "action is not possible because you have unmerged files"

On Wed, Jan 19 2022, Bagas Sanjaya wrote:
Show 33 quoted lines
> Factor action names (cherry-picking, committing, merging, pulling, and
> reverting) out of the message string.
>
> Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
> ---
>  advice.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/advice.c b/advice.c
> index 1dfc91d176..4c72856478 100644
> --- a/advice.c
> +++ b/advice.c
> @@ -175,15 +175,15 @@ void list_config_advices(struct string_list *list, const char *prefix)
>  int error_resolve_conflict(const char *me)
>  {
>  	if (!strcmp(me, "cherry-pick"))
> -		error(_("Cherry-picking is not possible because you have unmerged files."));
> +		error(_("%s is not possible because you have unmerged files."), "Cherry-picking");
>  	else if (!strcmp(me, "commit"))
> -		error(_("Committing is not possible because you have unmerged files."));
> +		error(_("%s is not possible because you have unmerged files."), "Commiting");
>  	else if (!strcmp(me, "merge"))
> -		error(_("Merging is not possible because you have unmerged files."));
> +		error(_("%s is not possible because you have unmerged files."), "Merging");
>  	else if (!strcmp(me, "pull"))
> -		error(_("Pulling is not possible because you have unmerged files."));
> +		error(_("%s is not possible because you have unmerged files."), "Pulling");
>  	else if (!strcmp(me, "revert"))
> -		error(_("Reverting is not possible because you have unmerged files."));
> +		error(_("%s is not possible because you have unmerged files."), "Reverting");
>  	else
>  		error(_("It is not possible to %s because you have unmerged files."),
>  			me);

René correctly notes downthread that we shouldn't change this, we have plenty of these in git now to make these translatable to multiple languages.

Just a tip that if you are refactoring something like this in that way and we should change it, this is much nicer:

	error(_("%s is not possible because you have unmerged files."),
	     !strcmp(me, "cherry-pick") ? "Cherry-picking" :
             !strcmp(me, "commit") ? "Committing" :
             [...]

I.e. if we could do your proposed de-duplication we can also de-duplicate this whole else if chain in favor of a less verbose ternary operation.

Jean-Noël AVILA· Jan 19, 2022, 15:42 UTC · re: Bagas Sanjaya · lore

Re: [PATCH 2/2] advice: refactor "action is not possible because you have unmerged files"

On Wednesday, 19 January 2022 10:44:45 CET Bagas Sanjaya wrote:
Show 13 quoted lines
> Factor action names (cherry-picking, committing, merging, pulling, and
> reverting) out of the message string.
> 
> Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
> ---
>  advice.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/advice.c b/advice.c
> index 1dfc91d176..4c72856478 100644
> --- a/advice.c
> +++ b/advice.c
> @@ -175,15 +175,15 @@ void list_config_advices(struct string_list *list, 
const char *prefix)
>  int error_resolve_conflict(const char *me)
>  {
>  	if (!strcmp(me, "cherry-pick"))
> -		error(_("Cherry-picking is not possible because you 
have unmerged files."));
> +		error(_("%s is not possible because you have unmerged 
files."), "Cherry-picking");
>  	else if (!strcmp(me, "commit"))
> -		error(_("Committing is not possible because you have 
unmerged files."));
> +		error(_("%s is not possible because you have unmerged 
files."), "Commiting");
>  	else if (!strcmp(me, "merge"))
> -		error(_("Merging is not possible because you have 
unmerged files."));
> +		error(_("%s is not possible because you have unmerged 
files."), "Merging");
>  	else if (!strcmp(me, "pull"))
> -		error(_("Pulling is not possible because you have 
unmerged files."));
> +		error(_("%s is not possible because you have unmerged 
files."), "Pulling");
>  	else if (!strcmp(me, "revert"))
> -		error(_("Reverting is not possible because you have 
unmerged files."));
> +		error(_("%s is not possible because you have unmerged 
files."), "Reverting");
>  	else
>  		error(_("It is not possible to %s because you have 
unmerged files."),
>  			me);
> 

These strings don't qualify for factorization, because the words that you are extracting are English words that need to be translated. We can only extract words that are know to be constant, such as options, configuration, environment variables.

Playing grammar lego with sentences makes it impossible for translators to find a good translation.

JN
Junio C Hamano· Jan 19, 2022, 18:18 UTC · re: Jean-Noël AVILA · lore

Re: [PATCH 2/2] advice: refactor "action is not possible because you have unmerged files"

Jean-Noël AVILA <jn.avila@free.fr> writes:
> Playing grammar lego with sentences makes it impossible for translators to find 
> a good translation.
Well said.
Thanks.

← back to recent threads