Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with "t" function in /lib/fat_free_crm/i18n.rb #1102

Closed
connectGBI opened this issue May 9, 2023 · 2 comments · Fixed by #1144
Closed

Issue with "t" function in /lib/fat_free_crm/i18n.rb #1102

connectGBI opened this issue May 9, 2023 · 2 comments · Fixed by #1144

Comments

@connectGBI
Copy link

Hello,

I've had an issue with /lib/fat_free_crm/i18n.rb with the "t" function. I am extremely new to all of this, but I think i found a solution so it stops breaking. I was getting issues that said:

ArgumentError (wrong number of arguments (given 2, expected 1)):

Any time "t" was called with an argument that was an array. The app seems to work now.

Here's the code I used for the "t" function:

def t(*args)
if args.size == 1
super(args.first, default: args.first.to_s)
elsif args.second.is_a?(Hash)
if args.second.value?(Array)
options = args.second.each_with_object({}) do |(k, v), h|
h[k] = v.is_a?(Array) ? v.join(',') : v
end
super(args.first, **options)
else
super(*args)
end
elsif args.second.is_a?(Integer)
super(args.first, count: args.second)
else
super(args.first, value: args.second)
end
end

Is this an alright fix? Is it going to cause me problems down the road?

@ferrisoxide
Copy link
Contributor

ferrisoxide commented Jul 26, 2023

Had the same issue trying to get the app working locally. The fix I tried looks like this:

    def t(*args)
      if args.size == 1
        super(args.first, default: args.first.to_s)
      elsif args.second.is_a?(Hash)
        super(args.first, **args.second)
      elsif args.second.is_a?(Integer)
        super(args.first, count: args.second)
      else
        super(args.first, value: args.second)
      end
    end

It seems to work, but I'm also fairly new to FatFreeCRM - so I've not sure what's the best approach.

Code changes and specs for this are in PR #1139

@ferrisoxide
Copy link
Contributor

@connectGBI

I've split my fix into a separate PR (see #1144). If you're keen, maybe see if that works for you.

CloCkWeRX added a commit that referenced this issue Aug 6, 2023
Support for hash arguments in i18n. Fixes #1102
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants