- 16 9月, 2020 1 次提交
-
-
由 Jonathan Hefner 提交于
This disentangles the control flow between Action View's `translate` and I18n's `translate`. In doing so, it fixes a handful of corner cases, for which tests have now been added. It also reduces memory allocations, and improves speed when using a default: **Memory** ```ruby require "benchmark/memory" Benchmark.memory do |x| x.report("warmup") { translate(:"translations.foo"); translate(:"translations.html") } x.report("text") { translate(:"translations.foo") } x.report("html") { translate(:"translations.html") } x.report("text 1 default") { translate(:"translations.missing", default: :"translations.foo") } x.report("html 1 default") { translate(:"translations.missing", default: :"translations.html") } x.report("text 2 defaults") { translate(:"translations.missing", default: [:"translations.missing", :"translations.foo"]) } x.report("html 2 defaults") { translate(:"translations.missing", default: [:"translations.missing", :"translations.html"]) } end ``` Before: ``` text 1.240k memsize ( 0.000 retained) 13.000 objects ( 0.000 retained) 2.000 strings ( 0.000 retained) html 1.600k memsize ( 0.000 retained) 19.000 objects ( 0.000 retained) 2.000 strings ( 0.000 retained) text 1 default 4.728k memsize ( 1.200k retained) 39.000 objects ( 4.000 retained) 5.000 strings ( 0.000 retained) html 1 default 5.056k memsize ( 1.160k retained) 41.000 objects ( 3.000 retained) 4.000 strings ( 0.000 retained) text 2 defaults 7.464k memsize ( 2.392k retained) 54.000 objects ( 6.000 retained) 4.000 strings ( 0.000 retained) html 2 defaults 7.944k memsize ( 2.384k retained) 60.000 objects ( 6.000 retained) 4.000 strings ( 0.000 retained) ``` After: ``` text 952.000 memsize ( 0.000 retained) 9.000 objects ( 0.000 retained) 1.000 strings ( 0.000 retained) html 1.008k memsize ( 0.000 retained) 10.000 objects ( 0.000 retained) 1.000 strings ( 0.000 retained) text 1 default 2.400k memsize ( 40.000 retained) 24.000 objects ( 1.000 retained) 4.000 strings ( 0.000 retained) html 1 default 2.464k memsize ( 0.000 retained) 22.000 objects ( 0.000 retained) 2.000 strings ( 0.000 retained) text 2 defaults 3.232k memsize ( 0.000 retained) 30.000 objects ( 0.000 retained) 2.000 strings ( 0.000 retained) html 2 defaults 3.456k memsize ( 0.000 retained) 32.000 objects ( 0.000 retained) 2.000 strings ( 0.000 retained) ``` **Speed** ```ruby require "benchmark/ips" Benchmark.ips do |x| x.report("text") { translate(:"translations.foo") } x.report("html") { translate(:"translations.html") } x.report("text 1 default") { translate(:"translations.missing", default: :"translations.foo") } x.report("html 1 default") { translate(:"translations.missing", default: :"translations.html") } x.report("text 2 defaults") { translate(:"translations.missing", default: [:"translations.missing", :"translations.foo"]) } x.report("html 2 defaults") { translate(:"translations.missing", default: [:"translations.missing", :"translations.html"]) } end ``` Before: ``` text 35.685k (± 0.7%) i/s - 179.050k in 5.017773s html 28.569k (± 3.1%) i/s - 143.871k in 5.040128s text 1 default 13.953k (± 2.0%) i/s - 70.737k in 5.071651s html 1 default 12.507k (± 0.4%) i/s - 63.546k in 5.080908s text 2 defaults 9.103k (± 0.3%) i/s - 46.308k in 5.087323s html 2 defaults 8.570k (± 4.3%) i/s - 43.071k in 5.034322s ``` After: ``` text 36.694k (± 2.0%) i/s - 186.864k in 5.094367s html 30.415k (± 0.5%) i/s - 152.900k in 5.027226s text 1 default 18.095k (± 2.7%) i/s - 91.086k in 5.036857s html 1 default 15.934k (± 1.7%) i/s - 80.223k in 5.036085s text 2 defaults 12.179k (± 0.6%) i/s - 61.659k in 5.062910s html 2 defaults 11.193k (± 2.1%) i/s - 56.406k in 5.041433s ```
-
- 12 9月, 2020 1 次提交
-
-
由 Jonathan Hefner 提交于
This refactor incidentally fixes a corner case when `translate` is called with a block, the translation is missing, and `debug_missing_translation` is false. This commit adds a test for the above corner case, and additional tests for existing behavior.
-
- 10 9月, 2020 1 次提交
-
-
由 Jonathan Hefner 提交于
Prior to this commit, when a translation key indicated that the translation text was HTML, the value returned by `I18n.translate` would always be marked as `html_safe`. However, the value returned by `I18n.translate` could be an untrusted value directly from `options[:default]`. This commit ensures values directly from `options[:default]` are not marked as `html_safe`.
-
- 27 8月, 2020 1 次提交
-
-
由 Sean Doyle 提交于
This commit extends the `ActionView::Helpers#translate` (and by way of alias, `#t`) helper methods to accept blocks. When invoked with a block, the `translate` call will yield the translated text as its first block argument, along with the resolved translation key as its second: ```erb <%= translate(".key") do |translation, resolved_key| %> <span data-i18n-key="<%= resolved_key %>"><%= translation %></span> <% end %> ``` In cases where relative translation keys are foregone in lieu of fully qualified keys, or if the caller is not interested in the resolved key, the second block argument can be omitted: ```erb <%= translate("action.template.key") do |translation| %> <p><%= translation %></p> <p><%= translation %>, but a second time</p> <% end %> ``` A benefit of yielding the translation is that it enabled template-local variable re-use. Alternatively, [`Object#tap`][tap] could be used. Prior to this commit, however, the resolution of the translation key was internal to `ActionView`, and unavailable to the caller (unless they were willing to explicitly determine the resolved key themselves). By making it available as a block parameter, it could be used to annotate the translated value in the resulting elements. [tap]: https://ruby-doc.org/core-2.7.0/Object.html#method-i-tap
-
- 10 2月, 2020 1 次提交
-
-
由 Stefan Wrobel 提交于
```ruby I18n.translate('missing.translation', default: nil) # => nil helper.translate('missing.translation', default: nil) # Before # => "<span class=\"translation_missing\" title=\"translation missing: en.missing.translation\">Translation</span>" # After # => nil ```
-
- 05 2月, 2020 2 次提交
-
-
由 Ryuta Kamizono 提交于
-
由 Ryuta Kamizono 提交于
-
- 14 6月, 2019 1 次提交
-
-
由 Jean Boussier 提交于
It is sometimes expected of the `translate` methods to return a Hash, for instance it's the case of the `number.format` key. As such users might need to specify a Hash default, e.g. `translate(:'some.format', default: { separator: '.', delimiter: ',' })`. This works as expected with the `I18n.translate` methods, however `TranslationHelper#translate` apply `Array()` on the default value. As a result the default value end up as `[:separator, '.', :delimiter, ',']`.
-
- 22 3月, 2019 1 次提交
-
-
由 John Hawthorn 提交于
Many tests were using `render file:`, but were only testing the behaviour of `render template:` (file: just allows more paths/ is less secure then template:). The reason for so many `render file:` is probably that they were the old default. This commit replaces `render file:` with `render template:` anywhere the test wasn't specifically interested in using `render file:`.
-
- 07 2月, 2019 2 次提交
-
-
由 Aaron Patterson 提交于
-
由 Aaron Patterson 提交于
Now we can throw away the subclass and the generated methods will get GC'd too
-
- 30 1月, 2019 1 次提交
-
-
由 Aaron Patterson 提交于
The AV::Base constructor was too complicated, and this commit tightens up the parameters it will take. At runtime, AV::Base is most commonly constructed here: https://github.com/rails/rails/blob/94d54fa4ab641a0ddeb173409cb41cc5becc02a9/actionview/lib/action_view/rendering.rb#L72-L74 This provides an AV::Renderer instance, a hash of assignments, and a controller instance. Since this is the common case for construction, we should remove logic from the constructor that handles other cases. This commit introduces special constructors for those other cases. Interestingly, most code paths that construct AV::Base "strangely" are tests.
-
- 03 7月, 2018 1 次提交
-
-
由 Juan Broullon 提交于
-
- 26 1月, 2018 1 次提交
-
-
由 Daniel Colson 提交于
-
- 24 7月, 2017 1 次提交
-
-
由 Kir Shatrov 提交于
-
- 02 7月, 2017 1 次提交
-
-
由 Matthew Draper 提交于
This reverts commit 3420a145, reversing changes made to afb66a5a.
-
- 01 7月, 2017 1 次提交
-
-
由 Kir Shatrov 提交于
-
- 07 8月, 2016 2 次提交
-
-
由 Xavier Noria 提交于
-
由 Xavier Noria 提交于
The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
-
- 30 12月, 2015 1 次提交
-
-
由 Akshay Vishnoi 提交于
-
- 19 12月, 2015 1 次提交
-
-
由 Sameer Rahmani 提交于
`I18n.translate` helper will wrap the missing translation keys in a <span> tag only if `debug_missing_translation` configuration has a truthy value. Default value is `true`. For example in `application.rb`: # in order to turn off missing key wrapping config.action_view.debug_missing_translation = false
-
- 29 10月, 2015 1 次提交
-
-
由 Kasper Timm Hansen 提交于
It's already represented in the key name. Demonstrate with a test. Also test that the default isn't output.
-
- 19 9月, 2015 1 次提交
-
-
由 Kir Shatrov 提交于
-
- 24 8月, 2015 1 次提交
-
-
由 Ronak Jangir 提交于
-
- 05 5月, 2015 2 次提交
-
-
由 Bernard Potocki 提交于
-
由 Bernard Potocki 提交于
-
- 05 4月, 2015 1 次提交
-
-
由 Adam Prescott 提交于
4.2.1 introduced a change to the way `translate`/`t` works with an option of `default: [[]]`. In 4.2.0, this would give a default value of `[]`, but in 4.2.1, it leads to a missing translation. `default: [[]]` is again allowed for cases where a default of `[]` is needed. This addresses GitHub issue 19640.
-
- 21 3月, 2015 1 次提交
-
-
由 Rafael Mendonça França 提交于
Strip nils out of default translations. Fixes #19419
-
- 27 2月, 2015 1 次提交
-
-
由 Ulisses Almeida 提交于
The previous version of rails(4.2.0) you can pass objects to the default option of translation helper. For example: ```ruby t('foo', default: 1) ``` But on rails 4.2.1 version this kind of use stopped to work, because started only to accept String types. Now with this fix we can use orther value types on this helper again.
-
- 06 1月, 2015 1 次提交
-
-
由 Rafael Mendonça França 提交于
-
- 03 1月, 2015 1 次提交
-
-
由 Justin Coyne 提交于
Previously default translation keys that didn't end in `_html`, but came after a missing key that ended in `_html` were being returned as html_safe. Now they are not. Fixes #18257
-
- 19 11月, 2014 1 次提交
-
-
由 Christopher Dell 提交于
Previously, when the `:raise` options was set to `false`, it would get overwritten to `true`, preventing custom exception handlers to be used.
-
- 06 9月, 2014 1 次提交
-
-
由 Rajarshi Das 提交于
not required include ActionView::Helpers::TagHelper in test as well
-
- 14 6月, 2014 1 次提交
-
-
由 Zuhao Wan 提交于
-
- 13 5月, 2014 2 次提交
-
-
由 Carlos Antonio da Silva 提交于
-
由 Josep Jaume Rey 提交于
`options[:default]` and `options[:raise]` can be mistakenly added to the `options` hash. This can be a problem if you're reusing the same object.
-
- 27 1月, 2014 1 次提交
-
-
由 Kassio Borges 提交于
Add a config to setup whether raise exception for missing translation or not.
-
- 05 12月, 2013 1 次提交
-
-
由 Shota Fukumori (sora_h) 提交于
Before ec16ba75, ActionView::Helpers::TranslationHelper#translate has raised errors with specifying options[:raise] to true. This should work by this fix: begin t(:"translations.missing", raise: true) rescue I18n::MissingTranslationData p :hello! end
-
- 03 12月, 2013 1 次提交
-
-
由 Michael Koziarski 提交于
i18n doesn't depend on active support which means it can't use our html_safe code to do its escaping when generating the spans. Rather than try to sanitize the output from i18n, just revert to our old behaviour of rescuing the error and constructing the tag ourselves. Fixes: CVE-2013-4491
-
- 20 6月, 2013 1 次提交
-
-
由 Piotr Sarnacki 提交于
-