I18n implemented and russian support added. #109

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
5 participants
@MrHant

MrHant commented Mar 12, 2011

Hi,

Implementation of I18n.
Includes:

  • custom locale files in config/locales gem folder
  • custom pluralization for different locales ('ru' pluralization should be different from 'en' one)

This commit shouldn't change current behavior of En locale and I think is pretty clear.

Hopefully it will suite your needs.

Best Regards,
Artyom S.

@vdmgolub

This comment has been minimized.

Show comment
Hide comment
@vdmgolub

vdmgolub May 4, 2011

Incorrect "previous" translation: should be "← Пред."

Incorrect "previous" translation: should be "← Пред."

This comment has been minimized.

Show comment
Hide comment
@MrHant

MrHant May 4, 2011

Owner

Упс. Согласен.

Owner

MrHant replied May 4, 2011

Упс. Согласен.

This comment has been minimized.

Show comment
Hide comment

np :)

@vdmgolub

This comment has been minimized.

Show comment
Hide comment
@vdmgolub

vdmgolub May 4, 2011

Incorrect "next" translation: should be "След. →"

Incorrect "next" translation: should be "След. →"

@komba

This comment has been minimized.

Show comment
Hide comment
@komba

komba May 26, 2011

It doesn't working.
ru.yml:

ru:
  will_paginate:
    pagination_options:
      previous: "← Пред."
      next: 'След. →'

code:

= will_paginate @stats
= I18n.t('will_paginate.pagination_options.previous')

output:
← Previous 1 2 Next →
← Пред.

I18n 0.5.0, rails 3.0.7

komba commented May 26, 2011

It doesn't working.
ru.yml:

ru:
  will_paginate:
    pagination_options:
      previous: "← Пред."
      next: 'След. →'

code:

= will_paginate @stats
= I18n.t('will_paginate.pagination_options.previous')

output:
← Previous 1 2 Next →
← Пред.

I18n 0.5.0, rails 3.0.7

@imkira

This comment has been minimized.

Show comment
Hide comment
@imkira

imkira Jul 27, 2011

MrHant, I really want this feature but when I was reading this part of the code I thought "it will be difficult to support new languages if we embed language specific conditions in the code" like this.
I propose a change, where we provide all context information which can be partially or fully used (via the interpolations variable) depending on the current specific language.
Something like:

interpolations = {
  :entry_name => entry_name,
  :plural_name => plural_name,
  :size => collection.size,
  :begin => collection.offset + 1,
  :end => collection.offset + collection.length,
  :total => collection.total_entries,
  :b => b,
  :eb => eb,
  :sp => sp
}

translation_key, default = 
  if collection.total_pages < 2
    case collection.size
    when 0; [ 'will_paginate.page_entries.nothing', "No #{plural_name} found" ]
    when 1; [ 'will_paginate.page_entries.one', "Displaying #{b}1#{eb} #{entry_name}" ]
    else; [ 'will_paginate.page_entries.other', "Displaying #{b}all #{collection.size}#{eb} #{plural_name}" ]
    end
  else
    [ 'will_paginate.page_entries.range', %{Displaying #{plural_name} #{b}%d#{sp}-#{sp}%d#{eb} of #{b}%d#{eb} in total} % [
      collection.offset + 1, collection.offset + collection.length, collection.total_entries ] ]
  end

I18n.t translation_key, interpolations.merge(:default => default)

What do you think about it?

MrHant, I really want this feature but when I was reading this part of the code I thought "it will be difficult to support new languages if we embed language specific conditions in the code" like this.
I propose a change, where we provide all context information which can be partially or fully used (via the interpolations variable) depending on the current specific language.
Something like:

interpolations = {
  :entry_name => entry_name,
  :plural_name => plural_name,
  :size => collection.size,
  :begin => collection.offset + 1,
  :end => collection.offset + collection.length,
  :total => collection.total_entries,
  :b => b,
  :eb => eb,
  :sp => sp
}

translation_key, default = 
  if collection.total_pages < 2
    case collection.size
    when 0; [ 'will_paginate.page_entries.nothing', "No #{plural_name} found" ]
    when 1; [ 'will_paginate.page_entries.one', "Displaying #{b}1#{eb} #{entry_name}" ]
    else; [ 'will_paginate.page_entries.other', "Displaying #{b}all #{collection.size}#{eb} #{plural_name}" ]
    end
  else
    [ 'will_paginate.page_entries.range', %{Displaying #{plural_name} #{b}%d#{sp}-#{sp}%d#{eb} of #{b}%d#{eb} in total} % [
      collection.offset + 1, collection.offset + collection.length, collection.total_entries ] ]
  end

I18n.t translation_key, interpolations.merge(:default => default)

What do you think about it?

mislav added a commit that referenced this pull request Jul 28, 2011

have no fear, i18n is here!
:previous_label, :next_label, page gap text and the `page_entries_info`
method output can now all be translated by overriding values seen in
"lib/will_paginate/locale/en.yml" from your own application locale files.

closes #99, #10, #109
@mislav

This comment has been minimized.

Show comment
Hide comment
@mislav

mislav Jul 28, 2011

Owner

Finally, i18n is in will_paginate for Rails 3. See https://github.com/mislav/will_paginate/blob/rails3/lib/will_paginate/locale/en.yml for values you can override.

I'm going to try to backport this to will_paginate 2.3.x for people running Rails 2.

I didn't pull this pull request because it creates a dependency to I18n while with my change I only rely on I18n if it's present, but also include defaults in the codebase.

Owner

mislav commented Jul 28, 2011

Finally, i18n is in will_paginate for Rails 3. See https://github.com/mislav/will_paginate/blob/rails3/lib/will_paginate/locale/en.yml for values you can override.

I'm going to try to backport this to will_paginate 2.3.x for people running Rails 2.

I didn't pull this pull request because it creates a dependency to I18n while with my change I only rely on I18n if it's present, but also include defaults in the codebase.

@mislav mislav closed this Jul 28, 2011

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