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

Pattern 'Update {modelClass}' with Yii::t() #246

Merged
merged 7 commits into from Aug 1, 2017

Conversation

bscheshirwork
Copy link
Contributor

The generator does not translate the model name.

$this->title = Yii::t('project', 'Update {modelClass}: ', [
    'modelClass' => 'Project',
]) . $model->name;

=>

$this->title = Yii::t('project', 'Update {modelClass}: ', [
    'modelClass' => Yii::t('project', 'Project'),
]) . $model->name;
Q A
Is bugfix? yes/no
New feature? yes/no

```
$this->title = Yii::t('project', 'Update {modelClass}: ', [
    'modelClass' => 'Project',
]) . $model->name;
```
=>
```
$this->title = Yii::t('project', 'Update {modelClass}: ', [
    'modelClass' => Yii::t('project', 'Project'),
]) . $model->name;
```
Copy link
Member

@samdark samdark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a line for changelog.

@samdark samdark added the type:enhancement Enhancement label Feb 13, 2017
@bscheshirwork
Copy link
Contributor Author

bscheshirwork commented Jul 28, 2017

Need a line for changelog.

something like this?

Eth #246: Translate modelClass for page title in CRUD generator (bscheshirwork)

@samdark
Copy link
Member

samdark commented Jul 28, 2017

Yes, something like that.

@samdark
Copy link
Member

samdark commented Jul 28, 2017

Would you please push it to the branch?

@@ -16,7 +16,9 @@
/* @var $this yii\web\View */
/* @var $model <?= ltrim($generator->modelClass, '\\') ?> */

$this->title = <?= $generator->generateString('Update {modelClass}: ', ['modelClass' => Inflector::camel2words(StringHelper::basename($generator->modelClass))]) ?> . $model-><?= $generator->getNameAttribute() ?>;
$this->title = <?= strtr($generator->generateString('Update {modelClass}: ', ['modelClass' => '{modelClass}']), [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it more, how about generating just Yii::t('app', 'Update Post')?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it more, how about generating just Yii::t('app', 'Update Post')?

contr: I think this pattern applied for many model in one translate part.

[
    'Update {modelClass}' => 'Обновить {modelClass}',
    'Model1' => 'Модель1',
    'Model2' => 'Модель2',
]

and 'Model1', 'Model2' can be use in another place

pro: create already have Yii::t('app', 'Create Post')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is necessary to bring both to one form

[
    'Update {modelClass}' => 'Обновить {modelClass}',
    'Create {modelClass}' => 'Создать {modelClass}',
    'Model1' => 'Модель1',
    'Model2' => 'Модель2',
]

or

    'Update Model1' => 'Обновить Модель1',
    'Create Model1' => 'Создать Модель1',
    'Update Model2' => 'Обновить Модель2',
    'Create Model2' => 'Создать Модель2',

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While Yii::t('app', 'Create Post') means more translation work, translation itself could be much better because you have more context in place.

Copy link
Member

@cebe cebe Jul 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am for putting it together. In languages, where different forms are necessary dependent on the grammatical gender of a word this will produce problems, e.g.:

'Create a Post'  => 'Einen Beitrag erstellen',
'Create an Annotation' => 'Eine Anmerkung erstellen',

Eine vs. Einen and even in english there is a and an if you want to add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And may be add
to translating pattern a number/name/other_key
$model-><?= $generator->getNameAttribute() ?>
of model?

Yii::t('app', 'Update Post {name}', ['name' => $model->id])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's fine to add it.

@samdark samdark added this to the 2.0.6 milestone Aug 1, 2017
@samdark samdark merged commit 866727e into yiisoft:master Aug 1, 2017
@samdark
Copy link
Member

samdark commented Aug 1, 2017

Merged. Thank you!

@bscheshirwork bscheshirwork deleted the patch-1 branch August 1, 2017 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants