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

Add field has_many i18n #2114

Merged
merged 1 commit into from
Feb 2, 2022
Merged

Add field has_many i18n #2114

merged 1 commit into from
Feb 2, 2022

Conversation

jhang-jhe-wei
Copy link
Contributor

Field::HasMany i18n

How to Use?

If you have ActiveRecord i18n translation of the model you don't need to do anything extra, if not, make an ActiveRecord i18n translation of the model.

Example

The recipe has many recipe items.

app/dashboards/recipe_dashboard.rb

  ATTRIBUTE_TYPES = {
    recipe_items: Field::HasMany,
    id: Field::Number,
    name: Field::String,
    package_spec: Field::String,
    remark: Field::String,
    created_at: Field::DateTime,
    updated_at: Field::DateTime,
  }.freeze

zh-TW.yml

zh-TW:
  activerecord:
    models:
      recipe: 配方表
      recipe_item: 材料

Result

image

材料種類 is defined in helper.label.recipe.recipe_items, it's not the same, don't confuse.

Copy link
Collaborator

@pablobm pablobm left a comment

Choose a reason for hiding this comment

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

Thank you for this :-) Just one thing that I think can be improved.

app/views/fields/has_many/_index.html.erb Outdated Show resolved Hide resolved
@pablobm
Copy link
Collaborator

pablobm commented Jan 27, 2022

@jhang-jhe-wei - Could you please rebase? The specs (I don't know why) are failing and I can't merge, but it looks like a rebase should fix it.

@nickcharlton nickcharlton force-pushed the main branch 2 times, most recently from 90815b2 to 2a1a6cf Compare February 2, 2022 13:11
If you have ActiveRecord i18n translation of the model you don't need to do
anything extra, if not, make an ActiveRecord i18n translation of the model.

e.g.:

The recipe has many recipe items.

```ruby
ATTRIBUTE_TYPES = {
  recipe_items: Field::HasMany,
  id: Field::Number,
  name: Field::String,
  package_spec: Field::String,
  remark: Field::String,
  created_at: Field::DateTime,
  updated_at: Field::DateTime,
}.freeze
```

```yaml
zh-TW:
  activerecord:
    models:
      recipe: 配方表
      recipe_item: 材料
```
@nickcharlton
Copy link
Member

Thanks for opening this PR! I rebased and tidied up the commit so we could get it merged.

@nickcharlton nickcharlton merged commit cfef37b into thoughtbot:main Feb 2, 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

Successfully merging this pull request may close these issues.

3 participants