From 8ef6aee3925323ba834d097f907ef974c3d7e8c7 Mon Sep 17 00:00:00 2001 From: Tom Tuddenham Date: Thu, 3 Aug 2023 08:35:53 +0930 Subject: [PATCH 1/2] Support for hash arguments in i18n. Fixes #1102 --- lib/fat_free_crm/i18n.rb | 2 +- spec/lib/fat_free_crm/i18n.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 spec/lib/fat_free_crm/i18n.rb diff --git a/lib/fat_free_crm/i18n.rb b/lib/fat_free_crm/i18n.rb index 3261fe9e61..f3cd817d89 100644 --- a/lib/fat_free_crm/i18n.rb +++ b/lib/fat_free_crm/i18n.rb @@ -14,7 +14,7 @@ def t(*args) if args.size == 1 super(args.first, default: args.first.to_s) elsif args.second.is_a?(Hash) - super(*args) + super(args.first, **args.second) elsif args.second.is_a?(Integer) super(args.first, count: args.second) else diff --git a/spec/lib/fat_free_crm/i18n.rb b/spec/lib/fat_free_crm/i18n.rb new file mode 100644 index 0000000000..c4779059d0 --- /dev/null +++ b/spec/lib/fat_free_crm/i18n.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +# Copyright (c) 2008-2013 Michael Dvorkin and contributors. +# +# Fat Free CRM is freely distributable under the terms of MIT license. +# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php +#------------------------------------------------------------------------------ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe 'I18n.t()' do + + class TestController < ActionController::Base + include FatFreeCRM::I18n + end + + let(:entity_string) { 'entities' } + let(:hidden_count) { 10 } + let(:test_controler) { TestController.new } + + it 'should translate hash arguments' do + expect(test_controler.t(:not_showing_hidden_entities, entity: entity_string, count: hidden_count)) + .to eq("Not showing 10 hidden entities.") + end +end From 4c68ecd5aae6ea42cdb356efba867c3409362274 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 6 Aug 2023 22:55:30 +0930 Subject: [PATCH 2/2] Apply suggestions from code review --- spec/lib/fat_free_crm/i18n.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/fat_free_crm/i18n.rb b/spec/lib/fat_free_crm/i18n.rb index c4779059d0..2a1c32745c 100644 --- a/spec/lib/fat_free_crm/i18n.rb +++ b/spec/lib/fat_free_crm/i18n.rb @@ -15,10 +15,10 @@ class TestController < ActionController::Base let(:entity_string) { 'entities' } let(:hidden_count) { 10 } - let(:test_controler) { TestController.new } + let(:test_controller) { TestController.new } it 'should translate hash arguments' do - expect(test_controler.t(:not_showing_hidden_entities, entity: entity_string, count: hidden_count)) + expect(test_controller.t(:not_showing_hidden_entities, entity: entity_string, count: hidden_count)) .to eq("Not showing 10 hidden entities.") end end