Namespacesd Models and model_name.human/human_attribute_for #39

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

I'm just localizing Humpyard and as it has namespaced models like Humpyard::Elements::TextElement it would be in the I18n yml:

activerecord:
  models:
    humpyard/elements/text_element: 'Text Element'
  attributes:
    humpyard/elements/text_element:
      content: 'Content'
      display_from: 'Display from'

This ist not very nice to read and I would have to redefine common fields like "display_from", which exists for all Humpyard::Elements:: models.
So I wrote a patch where the namespaced model translation could be in a namespaced yml/format:

activerecord:
  models:
    humpyard:
      elements:
        text_element: 'Text element'
  attributes:
    humpyard:
      elements:
        display_from: 'Display from'
        text_element:
          content: 'Content'

Note the fallback to 'activerecord.attributes.humpyard.elements.display_from for the common field. This is of course a simple example - when you have many Humpyard::Pages::* and Humpyard::Elements::* this syntax makes much more sense than it may look like. ;-)

CU
StarPeak

@starpeak starpeak Lookup I18n human_name and human_attribute_name for namespaced models…
… in namespaced I18n translations for ActiveModels; Fallback to namespace attributes on human_attribute_name for ActiveModels;
4066ac0

Ok - should have had a deeper look into the tickets :-)

The patch is much more improved than mine - but misses the fallback to module's attribute_name lookup.
As I found out there are often the same attributes inside a module I think it would be a good idea to implement it in that patch.
If you would like I would implement that into the patch from the ticket 5572.

Member

josevalim commented Sep 21, 2010

Please do provide another patch in that ticket. You can consider that your patch will be applied after the one already attached there.

Ok - I than would expand the given patch later the day as I have to go to a customer now. I think it will be in lighthouse in about 10 hours.
The code is almost there (I think I could take the loop from this commit using the i18n_key function) and I would even write a test for it this time. :-)

Member

josevalim commented Sep 21, 2010

Awesome! And writing a test is your only option! ;)

I took the option to write tests and pushed changes here as well as as a patch on lighthouse in the corresponding bug.

Also the tests from the patch were not running as PersonModule::Person.new does not take argument_hash - so I fixed that, too.

And github is telling me, that it only lasted 8 hours to publish the patch, not 10 as estimated. ;-)

Hi

Did you see the patch in https://rails.lighthouseapp.com/projects/8994/tickets/5572 ?
I just ask because you didn't respond and I assume that you just lost track on the ticket :)

Sven

Member

josevalim commented Sep 30, 2010

Yes, I am aware of the changes in the ticket! I just need to find sometime to discuss it with other core members as I am not sure if we want to make the errors messages lookup slower than it already is today.

For me it is more important to have the fallback on attribute names than on error messages - I just did the error messages part to complete the fallback cases.
Error messages are either the standard values for the type, could easily be set to non default I18n-Stings in validations (e.g. the :cannot_be_before_display_from error in the PublishRangeValidator in Humpyard) or are model specific in the most cases.

@vijaydev vijaydev added a commit that referenced this pull request Sep 27, 2011

@nhocki @vijaydev nhocki + vijaydev Alert about the new Bundler require for asset gems
If you are coming from a Rails 3.0 application, you won't have
the correct Bundler require statement.

This will cause the gems under the `assets` group not to be available
in the development and production environment.

I think this is related to the issue #39 in rails-sass
rails/sass-rails#39
0b151a4

@andhapp andhapp pushed a commit to andhapp/rails that referenced this pull request Sep 27, 2011

@nhocki nhocki Alert about the new Bundler require for asset gems
If you are coming from a Rails 3.0 application, you won't have
the correct Bundler require statement.

This will cause the gems under the `assets` group not to be available
in the development and production environment.

I think this is related to the issue #39 in rails-sass
rails/sass-rails#39
94ed1e2

@kalys kalys added a commit to kalys/rails that referenced this pull request Sep 9, 2012

@kalys kalys &#39 dates back to SGML when &#x27 was introduced in HTML 4.0 fcca118

@kalys kalys added a commit to kalys/rails that referenced this pull request Sep 9, 2012

@kalys kalys &#39 dates back to SGML when &#x27 was introduced in HTML 4.0 6b2a24c

@carlosantoniodasilva carlosantoniodasilva added a commit that referenced this pull request Sep 9, 2012

@carlosantoniodasilva carlosantoniodasilva Merge pull request #7513 from kalys/master
ERB::Util.html_escape encodes single quote as #39. Decimal form has better support in old browsers.
be8685d

@seuros seuros pushed a commit to seuros/django that referenced this pull request Aug 12, 2014

@guilleiguaran guilleiguaran Merge pull request #39 from larrylv/update-readme
Update README for currently supported adapters.
f5c85dc

@a-warner a-warner added a commit to Genius/rails2 that referenced this pull request Jul 15, 2015

@a-warner a-warner Fix sanitize spec
- In Ruby 1:

>> CGI.escapeHTML("'")
=> "'"

- in Ruby 2:

> CGI.escapeHTML("'")
=> "'"

Ruby 2 is correct, so this test spec should ensure that we're replacing
"'" with '
78a0609

@a-warner a-warner added a commit to Genius/rails2 that referenced this pull request Jul 15, 2015

@a-warner a-warner Fix sanitize spec
- In Ruby 1:

>> CGI.escapeHTML("'")
=> "'"

- in Ruby 2:

> CGI.escapeHTML("'")
=> "'"

Ruby 2 is correct, so this test spec should ensure that we're replacing
"'" with '
c3695df

@a-warner a-warner added a commit to Genius/rails2 that referenced this pull request Jul 15, 2015

@a-warner a-warner Fix sanitize spec
- In Ruby 1:

>> CGI.escapeHTML("'")
=> "'"

- in Ruby 2:

> CGI.escapeHTML("'")
=> "'"

Ruby 2 is correct, so this test spec should ensure that we're replacing
"'" with '
fbae973

@dhh dhh pushed a commit to dhh/rails that referenced this pull request Dec 14, 2015

@rafaelfranca rafaelfranca Merge pull request #39 from maclover7/patch-1
Update README.md
0223870

@vijaydev vijaydev pushed a commit that referenced this pull request Mar 6, 2016

@yui-knk yui-knk [ci skip] Fix `'id'` to be fixed-width font
As shown below, we should use <tt>...</tt> for string literal

```
$ echo "+'id'+" | rdoc --pipe
<p>+&#39;id&#39;+</p>

$ echo "<tt>'id'</tt>" | rdoc --pipe
<p><code>&#39;id&#39;</code></p>
```
c5b36a3

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment