Skip to contentSkip to conversation

More similar messages refactoring

PATCH In review Bagas Sanjaya 5 participants 8 messages Jan 19, 2022 – Feb 11, 2022

lore
Share & tools
lore
#0 lore raw

cover More similar messages refactoring

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/[email protected]/

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

Signature · 1 line
An old man doll... just what I always wanted! - Clara
#1 lore raw

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

Factor messages containing GIT_AUTHOR_* variable.

---
 sequencer.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
sequencer.c +6 -6
index 6abd72160c..472feb053c 100644
@@ -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;
Signature · 1 line
An old man doll... just what I always wanted! - Clara
#2 lore raw

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

#3 lore raw

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

In reply to Bagas Sanjaya

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

---
 advice.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
advice.c +5 -5
index 1dfc91d176..4c72856478 100644
@@ -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);
Signature · 1 line
An old man doll... just what I always wanted! - Clara
#4 lore raw

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:

Quoted 23 lines

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

---
 advice.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
advice.c +2 -3
index 1dfc91d176..4c72856478 100644
@@ -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."));

advice.c void list_config_advices(struct string_list *list, const char *prefix) · line 189

Quoted 10 lines
advice.c +3 -2
+		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é

#5 lore raw

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

In reply to Bagas Sanjaya
Quoted 23 lines · Bagas Sanjaya

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

---
 advice.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
advice.c +2 -3
index 1dfc91d176..4c72856478 100644
@@ -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."));

advice.c void list_config_advices(struct string_list *list, const char *prefix) · line 189

Quoted 10 lines
advice.c +3 -2
+		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.

#6 lore raw

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

In reply to Bagas Sanjaya

advice.c void list_config_advices(struct string_list *list,

Quoted 13 lines · On Wednesday, 19 January 2022 10:44:45 CET Bagas Sanjaya wrote:

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

---
 advice.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
advice.c +0 -0
index 1dfc91d176..4c72856478 100644
@@ -175,15 +175,15 @@ void list_config_advices(struct string_list *list, 

const char *prefix)

advice.c void list_config_advices(struct string_list *list, const char *prefix)

Quoted 4 lines
advice.c +0 -1
 int error_resolve_conflict(const char *me)
 {
 	if (!strcmp(me, "cherry-pick"))
-		error(_("Cherry-picking is not possible because you 

have unmerged files."));

advice.c void list_config_advices(struct string_list *list, · line 178

Quoted 1 line
advice.c +1 -0
+		error(_("%s is not possible because you have unmerged 

files."), "Cherry-picking");

advice.c void list_config_advices(struct string_list *list, · line 180

Quoted 2 lines
advice.c +0 -1
 	else if (!strcmp(me, "commit"))
-		error(_("Committing is not possible because you have 

unmerged files."));

advice.c void list_config_advices(struct string_list *list, · line 180

Quoted 1 line
advice.c +1 -0
+		error(_("%s is not possible because you have unmerged 

files."), "Commiting");

advice.c void list_config_advices(struct string_list *list, · line 182

Quoted 2 lines
advice.c +0 -1
 	else if (!strcmp(me, "merge"))
-		error(_("Merging is not possible because you have 

unmerged files."));

advice.c void list_config_advices(struct string_list *list, · line 182

Quoted 1 line
advice.c +1 -0
+		error(_("%s is not possible because you have unmerged 

files."), "Merging");

advice.c void list_config_advices(struct string_list *list, · line 184

Quoted 2 lines
advice.c +0 -1
 	else if (!strcmp(me, "pull"))
-		error(_("Pulling is not possible because you have 

unmerged files."));

advice.c void list_config_advices(struct string_list *list, · line 184

Quoted 1 line
advice.c +1 -0
+		error(_("%s is not possible because you have unmerged 

files."), "Pulling");

advice.c void list_config_advices(struct string_list *list, · line 186

Quoted 2 lines
advice.c +0 -1
 	else if (!strcmp(me, "revert"))
-		error(_("Reverting is not possible because you have 

unmerged files."));

advice.c void list_config_advices(struct string_list *list, · line 186

Quoted 1 line
advice.c +1 -0
+		error(_("%s is not possible because you have unmerged 

files."), "Reverting");

advice.c void list_config_advices(struct string_list *list, · line 188

Quoted 2 lines
advice.c +0 -0
 	else
 		error(_("It is not possible to %s because you have 

unmerged files."),

advice.c void list_config_advices(struct string_list *list, · line 189

Quoted 2 lines
advice.c +0 -0
 			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

#7 lore raw

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

Quoted 2 lines · Jean-Noël AVILA

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

Well said.

Thanks.