Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,18 @@ Examples usage:
=> "Not found!"
```

The `t` method can be also used as `translate`:
The `t()` method can be also used as `translate()`:

```ruby
MiniI18n.translate(:hello)
```

Or even using the global shortcut `T()`:

```ruby
T(:hello)
```

It accepts the following options:

* `locale`
Expand Down Expand Up @@ -240,7 +246,7 @@ And then, you get:

### Localization

You can also use the `MiniI18n.l` (or the long version `MiniI18n.localize`) method to localize your dates, time and numbers.
You can also use the `MiniI18n.l()` (or the long version `MiniI18n.localize()` or the global shorcut `L()`) method to localize your dates, time and numbers.

#### Dates and time

Expand Down
1 change: 1 addition & 0 deletions lib/mini_i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "mini_i18n/utils"
require "mini_i18n/localization"
require "mini_i18n/pluralization"
require "mini_i18n/kernel_extensions"

module MiniI18n
class << self
Expand Down
11 changes: 11 additions & 0 deletions lib/mini_i18n/kernel_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Global shortcuts for MiniI18n convenience methods

module Kernel
def T(*args)
MiniI18n.t(*args)
end

def L(*args)
MiniI18n.l(*args)
end
end
24 changes: 24 additions & 0 deletions spec/kernel_extensions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
RSpec.describe 'Global shortcuts' do
describe 'T method' do
it 'acts as a shortcut for MiniI18n.t' do
expect(T(:hello)).to eq 'hello'
expect(T(:hello, locale: :fr)).to eq 'bonjour'
end

it 'supports all the same options as MiniI18n.t' do
expect(T('hello_interpolation', name: 'world')).to eq 'hello world'
expect(T('notifications', count: 1)).to eq '1 unread notification'
expect(T('non_existent_key', default: 'default')).to eq 'default'
end
end

describe 'L method' do
it 'acts as a shortcut for MiniI18n.l' do
expect(L(1000.25)).to eq '1,000.25'
end

it 'supports all the same options as MiniI18n.l' do
expect(L(1000, as: :currency)).to eq '1,000 $'
end
end
end