Skip to contentSkip to conversation

mkfs i18n:

PATCH New Carlos Maiolino 3 participants 7 messages Sep 6, 2011 – Sep 22, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 mkfs i18n:

Use rpmatch() function to get answer to
yes-or-no questions during mkfs confirmation

---
 gfs2/mkfs/main_mkfs.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)
gfs2/mkfs/main_mkfs.c +22 -8
index 4751f19..d68cf98 100644
@@ -456,8 +456,11 @@ fail:
 
 static void are_you_sure(struct gfs2_sbd *sdp)
 {
-	char input[32];
+	char *line = NULL;
+	size_t len = 0;
 	int fd;
+	int ret = -1;
+	int res = 0;
 
 	fd = open(sdp->device_name, O_RDONLY|O_CLOEXEC);
 	if (fd < 0)
@@ -465,14 +468,25 @@ static void are_you_sure(struct gfs2_sbd *sdp)
 	printf( _("This will destroy any data on %s.\n"), sdp->device_name);
 	check_dev_content(sdp->device_name);
 	close(fd);
-	printf( _("\nAre you sure you want to proceed? [y/n] "));
-	if(!fgets(input, 32, stdin))
-		die( _("unable to read from stdin\n"));
+	
+	do{
+		printf( _("\nAre you sure you want to proceed? [y/n]"));
+		ret = getline(&line, &len, stdin);
+		res = rpmatch(line);
+		
+		if (res > 0){
+			free(line);
+			return;
+		}
+		if (!res){
+			printf("\n");
+			die( _("aborted\n"));
+		}
+		
+	}while(ret >= 0);
 
-	if (input[0] != 'y')
-		die( _("aborted\n"));
-	else
-		printf("\n");
+	if(line)
+		free(line);
 }
 
 /**
Signature · 1 line
1.7.6
#1 lore raw

PATCH 3/3 mkfs i18n:

Hi Carlos,

----- Original Message -----

| + do{
| + printf( _("\nAre you sure you want to proceed? [y/n]"));
| + ret = getline(&line, &len, stdin);
| + res = rpmatch(line);

I'd like to see the free(line); moved right here after rpmatch. Otherwise multiple iterations through the loop will leak memory.

| +
| + if (res > 0){

With my suggestion above, this can be removed:
| + free(line);

Other than that, it looks good.

Regards,

Bob Peterson
Red Hat File Systems

#2 lore raw

PATCH 3/3 mkfs i18n:

In reply to Carlos Maiolino

Hi,

Quoted 26 lines · Carlos Maiolino

Use rpmatch() function to get answer to
yes-or-no questions during mkfs confirmation

---
 gfs2/mkfs/main_mkfs.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)
gfs2/mkfs/main_mkfs.c +4 -1
index 4751f19..d68cf98 100644
@@ -456,8 +456,11 @@ fail:
 
 static void are_you_sure(struct gfs2_sbd *sdp)
 {
-	char input[32];
+	char *line = NULL;
+	size_t len = 0;
 	int fd;
+	int ret = -1;
+	int res = 0;
 
 	fd = open(sdp->device_name, O_RDONLY|O_CLOEXEC);
 	if (fd < 0)

gfs2/mkfs/main_mkfs.c static void are_you_sure(struct gfs2_sbd *sdp) · line 473

Quoted 9 lines
gfs2/mkfs/main_mkfs.c +3 -3
@@ -465,14 +468,25 @@ static void are_you_sure(struct gfs2_sbd *sdp)
 	printf( _("This will destroy any data on %s.\n"), sdp->device_name);
 	check_dev_content(sdp->device_name);
 	close(fd);
-	printf( _("\nAre you sure you want to proceed? [y/n] "));
-	if(!fgets(input, 32, stdin))
-		die( _("unable to read from stdin\n"));
+	
+	do{
+		printf( _("\nAre you sure you want to proceed? [y/n]"));

This means that the translator needs to know that rpmatch is being used and to also know how to translate this accordingly. Why not use nl_langinfo() to put the response strings into this message?

Also, starting the string with \n is a bit odd too,

Steve.

Quoted 23 lines
gfs2/mkfs/main_mkfs.c +15 -4
+		ret = getline(&line, &len, stdin);
+		res = rpmatch(line);
+		
+		if (res > 0){
+			free(line);
+			return;
+		}
+		if (!res){
+			printf("\n");
+			die( _("aborted\n"));
+		}
+		
+	}while(ret >= 0);
 
-	if (input[0] != 'y')
-		die( _("aborted\n"));
-	else
-		printf("\n");
+	if(line)
+		free(line);
 }
 
 /**
#3 lore raw

PATCH 3/3 mkfs i18n:

Hi,

Quoted 26 lines · Steven Whitehouse

Hi,

Quoted 23 lines · Carlos Maiolino

Use rpmatch() function to get answer to
yes-or-no questions during mkfs confirmation

---
 gfs2/mkfs/main_mkfs.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)
gfs2/mkfs/main_mkfs.c +4 -1
index 4751f19..d68cf98 100644
@@ -456,8 +456,11 @@ fail:
 
 static void are_you_sure(struct gfs2_sbd *sdp)
 {
-	char input[32];
+	char *line = NULL;
+	size_t len = 0;
 	int fd;
+	int ret = -1;
+	int res = 0;
 
Quoted 16 lines

gfs2/mkfs/main_mkfs.c static void are_you_sure(struct gfs2_sbd *sdp) · line 473

Quoted 12 lines
gfs2/mkfs/main_mkfs.c +3 -3
 	fd = open(sdp->device_name, O_RDONLY|O_CLOEXEC);
 	if (fd < 0)
@@ -465,14 +468,25 @@ static void are_you_sure(struct gfs2_sbd *sdp)
 	printf( _("This will destroy any data on %s.\n"), sdp->device_name);
 	check_dev_content(sdp->device_name);
 	close(fd);
-	printf( _("\nAre you sure you want to proceed? [y/n] "));
-	if(!fgets(input, 32, stdin))
-		die( _("unable to read from stdin\n"));
+	
+	do{
+		printf( _("\nAre you sure you want to proceed? [y/n]"));

This means that the translator needs to know that rpmatch is being used and to also know how to translate this accordingly. Why not use nl_langinfo() to put the response strings into this message?

I was looking how nl_langinfo() works, and all it does to help with yes/no questions is to return a regex expression (like [^[SsyY].*) to be used to match the user's answer, it does not return a string or char value like yes/no (en_US) or sim/nao(pt_BR) we can use to replace the y/n in the question string.

The rpmatch() function takes advantage of nl_langinfo() internaly to match the customer's answer according to which l10n the system is set.

This way, even using nl_langinfo(), the translator person will still need to translate the y/n to s/n, since is not possible to use nl_langinfo to replace these values.

What we could do, is to create an auxiliar function to check the return of nl_langinfo(), and, according with this value, write an specific string (s/n, y/n, etc). But, imho, this could lead to an error prone condition during string creation.

What u think?

Cheers,

Signature · 1 line
--Carlos
#4 lore raw

PATCH 3/3 mkfs i18n:

Hi Steve, I was looking through some codes from GNU project, and here are some examples I found:

from fdisk tool (this is the latest version, but I think fdisk is not often updated):

/* Prompt the user to answer a yes or no question. */ int

command_line_prompt_boolean_question (const char* prompt) {
        char        *user_ans;
        StrList *possibilities = str_list_create (_("yes"), _("no"), NULL);
        user_ans = fdisk_command_line_get_word (_(prompt), _("no"), possibilities, 0);

        if (strcmp (user_ans, _("yes")) == 0)
                return 1;

        /* user answered no */
        return 0;
}

I found another idea in the gnu parted.

The GNU parted adds the rpmatch function as a library into the parted source code, and adds a regex expression to be translated into the .pot file:

<snip>
#: lib/rpmatch.c:147
msgid "^[yY]"
msgstr ""

#: lib/rpmatch.c:160
msgid "^[nN]"
msgstr ""

</snip>

Looking through both of the above codes, looks like there is no specific rule about how to translate "y/n" strings. In both cases these are translated via .pot file.

One suggestion, would be to split the string

"Are you sure? [y/n]"

in three different strings like:

"Are you sure?"
"yes"
"no"

This way would be more 'understandable' for translators than the current one.
Or, we can add to the .pot file a comment explaining what to do with this portion of translation.

Quoted 57 lines
Quoted 20 lines
Quoted 20 lines
---
 gfs2/mkfs/main_mkfs.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)
gfs2/mkfs/main_mkfs.c +4 -1
index 4751f19..d68cf98 100644
@@ -456,8 +456,11 @@ fail:
 
 static void are_you_sure(struct gfs2_sbd *sdp)
 {
-	char input[32];
+	char *line = NULL;
+	size_t len = 0;
 	int fd;
+	int ret = -1;
+	int res = 0;
 
Quoted 16 lines

gfs2/mkfs/main_mkfs.c static void are_you_sure(struct gfs2_sbd *sdp) · line 473

Quoted 12 lines
gfs2/mkfs/main_mkfs.c +3 -3
 	fd = open(sdp->device_name, O_RDONLY|O_CLOEXEC);
 	if (fd < 0)
@@ -465,14 +468,25 @@ static void are_you_sure(struct gfs2_sbd *sdp)
 	printf( _("This will destroy any data on %s.\n"), sdp->device_name);
 	check_dev_content(sdp->device_name);
 	close(fd);
-	printf( _("\nAre you sure you want to proceed? [y/n] "));
-	if(!fgets(input, 32, stdin))
-		die( _("unable to read from stdin\n"));
+	
+	do{
+		printf( _("\nAre you sure you want to proceed? [y/n]"));

This means that the translator needs to know that rpmatch is being used and to also know how to translate this accordingly. Why not use nl_langinfo() to put the response strings into this message?

I was looking how nl_langinfo() works, and all it does to help with yes/no questions is to return a regex expression (like [^[SsyY].*) to be used to match the user's answer, it does not return a string or char value like yes/no (en_US) or sim/nao(pt_BR) we can use to replace the y/n in the question string.

The rpmatch() function takes advantage of nl_langinfo() internaly to match the customer's answer according to which l10n the system is set.

This way, even using nl_langinfo(), the translator person will still need to translate the y/n to s/n, since is not possible to use nl_langinfo to replace these values.

What we could do, is to create an auxiliar function to check the return of nl_langinfo(), and, according with this value, write an specific string (s/n, y/n, etc). But, imho, this could lead to an error prone condition during string creation.

What u think?

Cheers,

Signature · 1 line
--Carlos
Signature · 1 line
--Carlos
#5 lore raw

PATCH 3/3 mkfs i18n:

Hi,

Quoted 47 lines · Carlos Maiolino

Hi Steve, I was looking through some codes from GNU project, and here are some examples I found:

from fdisk tool (this is the latest version, but I think fdisk is not often updated):

/* Prompt the user to answer a yes or no question. */ int

command_line_prompt_boolean_question (const char* prompt) {
        char        *user_ans;
        StrList *possibilities = str_list_create (_("yes"), _("no"), NULL);
        user_ans = fdisk_command_line_get_word (_(prompt), _("no"), possibilities, 0);

        if (strcmp (user_ans, _("yes")) == 0)
                return 1;

        /* user answered no */
        return 0;
}

I found another idea in the gnu parted.

The GNU parted adds the rpmatch function as a library into the parted source code, and adds a regex expression to be translated into the .pot file:

<snip>
#: lib/rpmatch.c:147
msgid "^[yY]"
msgstr ""

#: lib/rpmatch.c:160
msgid "^[nN]"
msgstr ""

</snip>

Looking through both of the above codes, looks like there is no specific rule about how to translate "y/n" strings. In both cases these are translated via .pot file.

One suggestion, would be to split the string

"Are you sure? [y/n]"

in three different strings like:

Quoted 10 lines

"Are you sure?"
"yes"
"no"

This way would be more 'understandable' for translators than the current one.
Or, we can add to the .pot file a comment explaining what to do with this portion of translation.

I prefer the longer string to splitting it, if we cannot get the translation automatically from glibc, which does appear to be the case. Also, I think adding a comment to the .pot to explain how to translate the question is a good idea. We should always be doing that where anything tricky is encountered,

Steve.

Quoted 59 lines
Quoted 58 lines
Quoted 21 lines
Quoted 21 lines
---
 gfs2/mkfs/main_mkfs.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)
gfs2/mkfs/main_mkfs.c +4 -1
index 4751f19..d68cf98 100644
@@ -456,8 +456,11 @@ fail:
 
 static void are_you_sure(struct gfs2_sbd *sdp)
 {
-	char input[32];
+	char *line = NULL;
+	size_t len = 0;
 	int fd;
+	int ret = -1;
+	int res = 0;
 
Quoted 16 lines

gfs2/mkfs/main_mkfs.c static void are_you_sure(struct gfs2_sbd *sdp) · line 473

Quoted 12 lines
gfs2/mkfs/main_mkfs.c +3 -3
 	fd = open(sdp->device_name, O_RDONLY|O_CLOEXEC);
 	if (fd < 0)
@@ -465,14 +468,25 @@ static void are_you_sure(struct gfs2_sbd *sdp)
 	printf( _("This will destroy any data on %s.\n"), sdp->device_name);
 	check_dev_content(sdp->device_name);
 	close(fd);
-	printf( _("\nAre you sure you want to proceed? [y/n] "));
-	if(!fgets(input, 32, stdin))
-		die( _("unable to read from stdin\n"));
+	
+	do{
+		printf( _("\nAre you sure you want to proceed? [y/n]"));

This means that the translator needs to know that rpmatch is being used and to also know how to translate this accordingly. Why not use nl_langinfo() to put the response strings into this message?

I was looking how nl_langinfo() works, and all it does to help with yes/no questions is to return a regex expression (like [^[SsyY].*) to be used to match the user's answer, it does not return a string or char value like yes/no (en_US) or sim/nao(pt_BR) we can use to replace the y/n in the question string.

The rpmatch() function takes advantage of nl_langinfo() internaly to match the customer's answer according to which l10n the system is set.

This way, even using nl_langinfo(), the translator person will still need to translate the y/n to s/n, since is not possible to use nl_langinfo to replace these values.

What we could do, is to create an auxiliar function to check the return of nl_langinfo(), and, according with this value, write an specific string (s/n, y/n, etc). But, imho, this could lead to an error prone condition during string creation.

What u think?

Cheers,

Signature · 1 line
--Carlos
#6 lore raw

PATCH 3/3 mkfs i18n:

In reply to Carlos Maiolino

Hi,

Quoted 55 lines · Carlos Maiolino

Hi,

Quoted 26 lines · Steven Whitehouse

Hi,

Quoted 23 lines · Carlos Maiolino

Use rpmatch() function to get answer to
yes-or-no questions during mkfs confirmation

---
 gfs2/mkfs/main_mkfs.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)
gfs2/mkfs/main_mkfs.c +4 -1
index 4751f19..d68cf98 100644
@@ -456,8 +456,11 @@ fail:
 
 static void are_you_sure(struct gfs2_sbd *sdp)
 {
-	char input[32];
+	char *line = NULL;
+	size_t len = 0;
 	int fd;
+	int ret = -1;
+	int res = 0;
 
Quoted 16 lines

gfs2/mkfs/main_mkfs.c static void are_you_sure(struct gfs2_sbd *sdp) · line 473

Quoted 12 lines
gfs2/mkfs/main_mkfs.c +3 -3
 	fd = open(sdp->device_name, O_RDONLY|O_CLOEXEC);
 	if (fd < 0)
@@ -465,14 +468,25 @@ static void are_you_sure(struct gfs2_sbd *sdp)
 	printf( _("This will destroy any data on %s.\n"), sdp->device_name);
 	check_dev_content(sdp->device_name);
 	close(fd);
-	printf( _("\nAre you sure you want to proceed? [y/n] "));
-	if(!fgets(input, 32, stdin))
-		die( _("unable to read from stdin\n"));
+	
+	do{
+		printf( _("\nAre you sure you want to proceed? [y/n]"));

This means that the translator needs to know that rpmatch is being used and to also know how to translate this accordingly. Why not use nl_langinfo() to put the response strings into this message?

I was looking how nl_langinfo() works, and all it does to help with yes/no questions is to return a regex expression (like [^[SsyY].*) to be used to match the user's answer, it does not return a string or char value like yes/no (en_US) or sim/nao(pt_BR) we can use to replace the y/n in the question string.

The rpmatch() function takes advantage of nl_langinfo() internaly to match the customer's answer according to which l10n the system is set.

This way, even using nl_langinfo(), the translator person will still need to translate the y/n to s/n, since is not possible to use nl_langinfo to replace these values.

Quoted 7 lines

What we could do, is to create an auxiliar function to check the return of nl_langinfo(), and, according with this value, write an specific string (s/n, y/n, etc). But, imho, this could lead to an error prone condition during string creation.

What u think?

Cheers,

It is is not possible to use glibc for this, then lets not worry about it too much. I just wanted to be certain that there was not some standard way to deal with these kinds of translations before we create our own solution to the problem,

Steve.