aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/locale
Commit message (Collapse)AuthorAgeFilesLines
* Improve the performance of `ActiveSupport::Inflector.ordinal`Ryuta Kamizono2018-04-291-9/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This improves the performance for the most ordinalized numbers (1st, 2nd, 3rd, etc). ``` require "benchmark/ips" def o1(number) abs_number = number.to_i.abs if (11..13).include?(abs_number % 100) "th" else case abs_number % 10 when 1; "st" when 2; "nd" when 3; "rd" else "th" end end end def o3(number) case number when 1; "st" when 2; "nd" when 3; "rd" when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th" else num_modulo = number.to_i.abs % 100 if 11 <= num_modulo && num_modulo <= 13 "th" else case num_modulo % 10 when 1; "st" when 2; "nd" when 3; "rd" else "th" end end end end def o4(number) case number when 1; "st" when 2; "nd" when 3; "rd" when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th" else num_modulo = number.to_i.abs % 100 num_modulo %= 10 if num_modulo > 13 case num_modulo when 1; "st" when 2; "nd" when 3; "rd" else "th" end end end puts RUBY_DESCRIPTION Benchmark.ips do |x| x.report("orig") { o1(1); o1(2); o1(3); o1(4); o1(11); o1(111); o1(1523) } x.report("ord3") { o3(1); o3(2); o3(3); o3(4); o3(11); o3(111); o3(1523) } x.report("ord4") { o4(1); o4(2); o4(3); o4(4); o4(11); o4(111); o4(1523) } x.compare! end ``` ``` ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin15] Warming up -------------------------------------- orig 25.305k i/100ms ord3 121.146k i/100ms ord4 124.944k i/100ms Calculating ------------------------------------- orig 275.496k (± 2.4%) i/s - 1.392M in 5.054720s ord3 1.649M (± 5.0%) i/s - 8.238M in 5.009801s ord4 1.700M (± 7.0%) i/s - 8.496M in 5.031646s Comparison: ord4: 1700059.6 i/s ord3: 1649154.9 i/s - same-ish: difference falls within error orig: 275496.3 i/s - 6.17x slower ``` Closes #25020. [lvl0nax, Jeremy Daer, Ryuta Kamizono]
* `ActiveSupport::Inflector#ordinal` and `ActiveSupport::Inflector#ordinalize`Christian Blais2018-03-051-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | now support translations through I18n. { fr: { number: { nth: { ordinals: lambda do |_key, number:, **_options| if number.to_i.abs == 1 'er' else 'e' end end, ordinalized: lambda do |_key, number:, **_options| "#{number}#{ActiveSupport::Inflector.ordinal(number)}" end } } } }
* Add support for Petabyte and Exabyte in number to human sizeAkshay Vishnoi2015-12-221-0/+2
|
* Remove i18n symbol dependencyChris McGrath2013-01-171-3/+3
| | | | | | | | | date.order is the only key in rails i18n that is required to be a symbol. This patch allows for symbols or strings which means: * No requirement for symbol type in .yml files. A future YAML.safe_load wouldn't need to load symbols * Rails could actually use json rather than yml as the backend
* Fallback to :en locale instead of handling a constant with defaultsCarlos Antonio da Silva2012-08-111-6/+4
| | | | | | | | Action Pack already comes with a default locale fine for :en, that is always loaded. We can just fallback to this locale for defaults, if values for the current locale cannot be found. Closes #4420, #2802, #2890.
* Moving NumberHelpers from ActionView to ActiveSupportAndrew Mutz2012-05-271-0/+99
|
* Deletes trailing whitespaces (over text files only find * -type f -exec sed ↵Santiago Pastorino2010-08-141-3/+3
| | | | 's/[ \t]*$//' -i {} \;)
* Fix comment in en.yml datime_select -> datetime_selectRodrigo Rosenfeld Rosas2010-06-201-1/+1
|
* fixing invalid yaml [#4418 state:resolved]Aaron Patterson2010-04-161-1/+4
| | | | Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* Change Array#to_sentence I18n options to pass comma and space character from ↵Akira Matsuda2008-12-081-2/+3
| | | | | | | | outside. [#1397 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* use :en as a default locale (in favor of :en-US)Sven Fuchs2008-11-181-1/+1
| | | | Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
* Made i18n simple backend able to store false values (and not confuse them ↵Tarmo Tänav2008-10-091-0/+1
| | | | | | | | | with nil or lack of value) Implemented support.array.skip_last_comma i18n key for Array#to_sentence, this also tests the ability to store false. Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
* Locale file changed to yamlIain Hecker2008-08-202-29/+31
|
* switch to using I18n.load_translations instead of requiring plain ruby filesSven Fuchs2008-08-131-24/+25
|
* Fixed Date and Time localization for ActiveSupportLuca Guidi2008-07-021-0/+21
|
* Renamed lang/ to locale/ because that's what we seem toSven Fuchs2008-06-211-0/+7
standarize on. Also, in future this place can be used for data/code that's not literally translations but conceptually belongs to the locale (like custom pluralization algorithms etc.).