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

Comment about consistency in Language strings #6341

Closed
tangix opened this issue Aug 5, 2022 · 10 comments
Closed

Comment about consistency in Language strings #6341

tangix opened this issue Aug 5, 2022 · 10 comments

Comments

@tangix
Copy link
Contributor

tangix commented Aug 5, 2022

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?

@paulbalandan
Copy link
Member

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 paulbalandan transferred this issue from codeigniter4/translations Aug 5, 2022
@tangix tangix closed this as completed Aug 5, 2022
@tangix tangix reopened this Aug 5, 2022
@tangix
Copy link
Contributor Author

tangix commented Aug 5, 2022

(Sorry, didn't see it was moved)

@tangix tangix changed the title Comment about consistency in strings Comment about consistency in Language strings Aug 5, 2022
@kenjis
Copy link
Member

kenjis commented Aug 6, 2022

Should maybe be standardized to one format?

I would like to if possible.

@MGatner
Copy link
Member

MGatner commented Aug 19, 2022

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

@tangix
Copy link
Contributor Author

tangix commented Aug 22, 2022

@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}.'

@MGatner
Copy link
Member

MGatner commented Aug 22, 2022

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);

@kenjis
Copy link
Member

kenjis commented Aug 22, 2022

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"

@paulbalandan
Copy link
Member

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.

@kenjis
Copy link
Member

kenjis commented Sep 2, 2022

Closed by #6474

@kenjis kenjis closed this as completed Sep 2, 2022
@MGatner
Copy link
Member

MGatner commented Sep 3, 2022

👏

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

No branches or pull requests

4 participants