CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

Comment about consistency in Language strings

Open tangix opened this issue 2 years ago • 3 comments

Just want to comment on the use of {0} in the strings: there are multiple ways of showing for example filenames in the messages: "{0}", ({0}), `{0}` or simply without quotes or parenthesis {0}

Should maybe be standardized to one format?

tangix avatar Aug 05 '22 05:08 tangix

I think this should be discussed in the main repository. So that if ever there will be changes there, those will just be cascaded here.

paulbalandan avatar Aug 05 '22 05:08 paulbalandan

(Sorry, didn't see it was moved)

tangix avatar Aug 05 '22 05:08 tangix

Should maybe be standardized to one format?

I would like to if possible.

kenjis avatar Aug 06 '22 13:08 kenjis

@tangix if you would like to take a first pass at that we would gratefully review your Pull Request!

MGatner avatar Aug 19 '22 10:08 MGatner

@tangix if you would like to take a first pass at that we would gratefully review your Pull Request!

I can work on that. Unfortunately I think this change will break backward compatibility when tests checking the error message will start to fail, please advise.

Personally I prefer "{0}" where the filename/value is in the text and simply {0} where it is obvious what the value signifies.

For example:

'Command "{0}" not found.'
'"{0}" class expected cookies array to be instances of "{1}" but got "{2}" at index {3}.'

and when separated by colon:

'Error while creating file: {0}'
'Failed to authenticate username. Error: {0}'

Also, I think errors should be written like this: 'Failed to parse json string, error: "{0}".' should be written 'Failed to parse json string. Error: {0}.'

tangix avatar Aug 22 '22 05:08 tangix

I'm good with all those opinions. I think the consistency is more important than the particular syntax (though I would probably do pretty much as you have suggested).

Language files and contents are intentionally internal, so no concerns about breaking changes. If a test is verifying a language response it should be using the function, not the text directly:

// this:
$this->assertSame(lang('Foo.bar', ['bam']), $result);
// not this:
$this->assertSame('Foo bar had a "bam"', $result);

MGatner avatar Aug 22 '22 10:08 MGatner

I think if the value (may) contains a space, it is better to quote with ".

Error while creating file: abc def.txt Error while creating file: "abc def.txt"

Error while creating file: abc def.txt Error while creating file: " abc def.txt"

kenjis avatar Aug 22 '22 11:08 kenjis

Personally I prefer "{0}" where the filename/value is in the text and simply {0} where it is obvious what the value signifies. Also, I think errors should be written like this: 'Failed to parse json string, error: "{0}".' should be written 'Failed to parse json string. Error: {0}.'

I'm both in favor.

paulbalandan avatar Aug 23 '22 02:08 paulbalandan

Closed by https://github.com/codeigniter4/CodeIgniter4/pull/6474

kenjis avatar Sep 02 '22 23:09 kenjis

👏

MGatner avatar Sep 03 '22 10:09 MGatner