From d9aa9875aeb078a6dadcd8989f3ea445251a696f Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <[email protected]>
Date: Mon, 14 Jul 2025 21:31:14 +0000
Subject: [PATCH 1/5] Initial plan
From 6c7bff5a1583d5c4c76a5a0a92b8766bb41effa4 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <[email protected]>
Date: Mon, 14 Jul 2025 21:35:56 +0000
Subject: [PATCH 2/5] Add global shortcuts T/t and L/l for MiniI18n methods
Co-authored-by: markets <[email protected]>
---
lib/mini_i18n.rb | 1 +
lib/mini_i18n/kernel.rb | 19 +++++++++++++++++
spec/kernel_spec.rb | 46 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 66 insertions(+)
create mode 100644 lib/mini_i18n/kernel.rb
create mode 100644 spec/kernel_spec.rb
diff --git a/lib/mini_i18n.rb b/lib/mini_i18n.rb
index 6e52bf7..775ce42 100644
--- a/lib/mini_i18n.rb
+++ b/lib/mini_i18n.rb
@@ -3,6 +3,7 @@
require "mini_i18n/utils"
require "mini_i18n/localization"
require "mini_i18n/pluralization"
+require "mini_i18n/kernel"
module MiniI18n
class << self
diff --git a/lib/mini_i18n/kernel.rb b/lib/mini_i18n/kernel.rb
new file mode 100644
index 0000000..17067f4
--- /dev/null
+++ b/lib/mini_i18n/kernel.rb
@@ -0,0 +1,19 @@
+module Kernel
+ # Global shortcuts for MiniI18n convenience methods
+
+ def T(*args)
+ MiniI18n.t(*args)
+ end
+
+ def t(*args)
+ MiniI18n.t(*args)
+ end
+
+ def L(*args)
+ MiniI18n.l(*args)
+ end
+
+ def l(*args)
+ MiniI18n.l(*args)
+ end
+end
\ No newline at end of file
diff --git a/spec/kernel_spec.rb b/spec/kernel_spec.rb
new file mode 100644
index 0000000..e8d3270
--- /dev/null
+++ b/spec/kernel_spec.rb
@@ -0,0 +1,46 @@
+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 't method' do
+ it 'acts as a shortcut for MiniI18n.t' do
+ expect(t(:hello)).to eq 'hello'
+ expect(t(:hello, locale: :es)).to eq 'hola'
+ 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: 0)).to eq 'no unread notifications'
+ 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
+
+ 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
\ No newline at end of file
From b15a73895a20a069f81642e95876546064410e0d Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <[email protected]>
Date: Mon, 14 Jul 2025 21:48:39 +0000
Subject: [PATCH 3/5] Refactor global shortcuts based on feedback: keep only
uppercase versions, rename file, update README
Co-authored-by: markets <[email protected]>
---
README.md | 23 +++++++++++++++++++
lib/mini_i18n.rb | 2 +-
.../{kernel.rb => kernel_extensions.rb} | 8 -------
spec/kernel_spec.rb | 22 ------------------
4 files changed, 24 insertions(+), 31 deletions(-)
rename lib/mini_i18n/{kernel.rb => kernel_extensions.rb} (63%)
diff --git a/README.md b/README.md
index 680761f..702e5f4 100644
--- a/README.md
+++ b/README.md
@@ -97,6 +97,29 @@ The `t` method can be also used as `translate`:
MiniI18n.translate(:hello)
```
+### Global shortcuts
+
+For convenience, `MiniI18n` provides global shortcuts that can be used anywhere in your application:
+
+* `T()` - shortcut for `MiniI18n.t()`
+* `L()` - shortcut for `MiniI18n.l()`
+
+These shortcuts work exactly like their full counterparts:
+
+```ruby
+# Translation shortcuts
+T(:hello)
+T(:hello, locale: :fr)
+T('hello_interpolation', name: 'world')
+T('notifications', count: 1)
+
+# Localization shortcuts
+L(1000.25)
+L(1000, as: :currency)
+```
+
+These global methods are injected into the `Kernel` module, making them available throughout your application without needing to prefix them with `MiniI18n.`.
+
It accepts the following options:
* `locale`
diff --git a/lib/mini_i18n.rb b/lib/mini_i18n.rb
index 775ce42..5d86faf 100644
--- a/lib/mini_i18n.rb
+++ b/lib/mini_i18n.rb
@@ -3,7 +3,7 @@
require "mini_i18n/utils"
require "mini_i18n/localization"
require "mini_i18n/pluralization"
-require "mini_i18n/kernel"
+require "mini_i18n/kernel_extensions"
module MiniI18n
class << self
diff --git a/lib/mini_i18n/kernel.rb b/lib/mini_i18n/kernel_extensions.rb
similarity index 63%
rename from lib/mini_i18n/kernel.rb
rename to lib/mini_i18n/kernel_extensions.rb
index 17067f4..3255451 100644
--- a/lib/mini_i18n/kernel.rb
+++ b/lib/mini_i18n/kernel_extensions.rb
@@ -5,15 +5,7 @@ def T(*args)
MiniI18n.t(*args)
end
- def t(*args)
- MiniI18n.t(*args)
- end
-
def L(*args)
MiniI18n.l(*args)
end
-
- def l(*args)
- MiniI18n.l(*args)
- end
end
\ No newline at end of file
diff --git a/spec/kernel_spec.rb b/spec/kernel_spec.rb
index e8d3270..9ba026c 100644
--- a/spec/kernel_spec.rb
+++ b/spec/kernel_spec.rb
@@ -12,18 +12,6 @@
end
end
- describe 't method' do
- it 'acts as a shortcut for MiniI18n.t' do
- expect(t(:hello)).to eq 'hello'
- expect(t(:hello, locale: :es)).to eq 'hola'
- 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: 0)).to eq 'no unread notifications'
- end
- end
-
describe 'L method' do
it 'acts as a shortcut for MiniI18n.l' do
expect(L(1000.25)).to eq '1,000.25'
@@ -33,14 +21,4 @@
expect(L(1000, as: :currency)).to eq '1,000 $'
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
\ No newline at end of file
From 7f6ffbea86f79e5e40021e03290a115a7fba812b Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <[email protected]>
Date: Mon, 14 Jul 2025 22:17:57 +0000
Subject: [PATCH 4/5] Update README docs to integrate global shortcuts into
existing sections
Co-authored-by: markets <[email protected]>
---
README.md | 21 +++------------------
1 file changed, 3 insertions(+), 18 deletions(-)
diff --git a/README.md b/README.md
index 702e5f4..ac57039 100644
--- a/README.md
+++ b/README.md
@@ -97,29 +97,12 @@ The `t` method can be also used as `translate`:
MiniI18n.translate(:hello)
```
-### Global shortcuts
-
-For convenience, `MiniI18n` provides global shortcuts that can be used anywhere in your application:
-
-* `T()` - shortcut for `MiniI18n.t()`
-* `L()` - shortcut for `MiniI18n.l()`
-
-These shortcuts work exactly like their full counterparts:
+The `t` method can be also used as global shortcut `T()`:
```ruby
-# Translation shortcuts
T(:hello)
-T(:hello, locale: :fr)
-T('hello_interpolation', name: 'world')
-T('notifications', count: 1)
-
-# Localization shortcuts
-L(1000.25)
-L(1000, as: :currency)
```
-These global methods are injected into the `Kernel` module, making them available throughout your application without needing to prefix them with `MiniI18n.`.
-
It accepts the following options:
* `locale`
@@ -265,6 +248,8 @@ And then, you get:
You can also use the `MiniI18n.l` (or the long version `MiniI18n.localize`) method to localize your dates, time and numbers.
+The `l` method can be also used as global shortcut `L()`:
+
#### Dates and time
It uses `strftime` under the hood. You should provide your localizations using the following format:
From c674598b702160af76f34111cb38a0068bb67be0 Mon Sep 17 00:00:00 2001
From: Marc Anguera Insa