Closed zachd closed 2 years ago
Thank you for your feedback! I wanted to double-check, how your translations look on Lokalise? Specifically, how placeholders are represented there? Do you use universal Lokalise placeholders?
As a quick fix, you could try using Custom placeholders https://docs.lokalise.com/en/articles/5781985-custom-placeholders and Universal placeholders https://docs.lokalise.com/en/articles/1400511-lokalise-placeholders. For example, if your translation on Lokalise has the following contents:
Welcome, [%s:name]
Then you can enable Custom placeholders and provide the following data:
%{
}
Then use Ruby on Rails YAML format and Raw placeholder format when exporting your data.
Thanks @bodrovis ! We uploaded the YAML files from Ruby, and converted them to Universal Placeholders.
For example [%1$s:current_weather] currently. It’s [%1$s:current_temp].
We got access to the Custom Placeholders app, but it doesn't seem to format the data correctly when exported.
Set up with these settings:
And exported as Raw in YAML format, we still get Universal Placeholders in the export, like greeting: 'Hello [%1$s:recipient],'
It might be that the Custom Placeholders app needs to be enabled before we import the translations to Lokalise the first time? Sadly this is not possible for us as the keys are already uploaded and translated.
How does this gem usually work with a Rails project and rails-i18n
, maybe you have an example project to show me?
Unfortunately I don't have any samples at hand, but let me try to double-check everything. It's strange because everything worked for me fine
Yeah you know it's not working with the placeholder you are currently using. However this approach is working fine
[%s:current_weather] currently. It’s [%s:current_temp]
Hi @bodrovis, are you suggesting that placeholder works in an en.yml
file on Rails?
Doesn't seem to work for me on rails console
:
I18n.backend.store_translations :en, { test_key: 'Example %{placeholder} here' }
I18n.translate('.test_key', placeholder: 'text')
=> "Example text here"
I18n.backend.store_translations :en, { test_key: 'Example [%s:placeholder] here' }
I18n.translate('.test_key', placeholder: 'text')
=> "Example [%s:placeholder] here"
No-no, here's an example.
Translation:
Configuration:
Download config:
Preview:
So, effectively my universal placeholders are presented as ordinary RoR YAML placeholders when using "raw" format
Ah okay! There must be something wrong with how we uploaded our YAML files before, I assumed [%1$s:current_weather]
was a universal placeholder processed by Lokalise.
Would you have a way to get this Rails gem working out-of-the-box with Lokalise? And without using the Custom Placeholders App so we don't need to fix all our translated strings (4k+) 😄
Actually [%1$s:current_weather]
should work as a universal placeholder - I'm not quite sure what's the problem, to be honest (I've asked other team members to look into it).
Also, the gem should be working out of the box with translations similar to this one:
What was the original translation you tried to export?..
I've actually added another test case https://github.com/bodrovis/lokalise_manager/commit/45ea2452571306a6f67e293bad0dadec6dd13cce#diff-ffcc6c7c9aa007b1bd12983b91222c59ddcfe6917e2fd1cf6cef519f1edc8ee6R124
So, if I have the following translation Welcome to the app, %{username}
on Lokalise, it gets exported as-is
Also, the gem should be working out of the box with translations similar to this one:
Could you explain how to get translations into Lokalise with those placeholders?
If I upload like this
with Convert to universal placeholders unchecked
I still get this result in the editor
I've actually added another test case https://github.com/bodrovis/lokalise_manager/commit/45ea2452571306a6f67e293bad0dadec6dd13cce#diff-ffcc6c7c9aa007b1bd12983b91222c59ddcfe6917e2fd1cf6cef519f1edc8ee6R124
And related to this, how did you get the placeholder %{username}
to output in your new test on this line?
I see the request parameters in the VCR cassette have placeholder_format: icu
defined, so I would expect {username}
as that's what I was receiving.
I believe this is happening because you've enabled Custom placeholders. If you turn it off, you should see a plain old placeholder %{user_first_name}
. Also, with the ICU format you'll get your %{}
placeholders exported as-is because Lokalise doesn't detect those as placeholders at all - that's how it works in my test case
Okay I see, it's a bit of a hack then 😉 If you changed the default of this gem to placeholder_format: raw
it would make more sense.
Let me know if you get an answer from the team working on Custom Placeholders to support all types of Universal Placeholders and it should be good. A few lines in the documentation to explain that Universal Placeholders are only compatible with Rails if you use a Lokalise App would be great too!
Unfortunately I don't think there's any easy solution with Custom placeholders, universal ones and Rails. If you need this feature, I'd suggest reporting it to the customer support team and they can forward it to product guys (it would be more appropriate as I'm not a member of CS). Also, I'll update the docs for Rails.
In any case, thank you for reporting this and I'm sorry it tooks us a while to sort things out!
Describe the bug Hello, the default
format: :ruby_yaml
andplaceholder_format: :icu
does not work with a Ruby on Rails project with the default i18n setup using therails-i18n
gem.Ruby on Rails expects placeholders to be
%{my_placeholder}
but this gem exports as{my_placeholder}
when using type:icu
.I cannot get any combination of
format
/placeholder_format
for the file export to work with this gem and a Ruby on Rails project. Can you confirm how to use this gem?To Reproduce
config/locales
folder of a Ruby on Rails project{my_placeholder}
when translating a string, instead of using the replaced variable. This is due to Rails expecting%{my_placeholder}
Expected behavior We expect that this gem should export as
%{my_placeholder}
, the only format supported by Ruby on Rails rails-i18n gem.Your environment:
Additional context See how placeholders work in i18n interpolation documentation https://guides.rubyonrails.org/i18n.html#passing-variables-to-translations
Checked with your support team to log a ticket, they suggested to go ahead. Thanks!