4 ms·
Ah ha, that's actually not the doing of Slim but rather my usage of I18n, the localisation system used in Rails. Whenever you see t("something.stuff") or I18n.t
by robotmay 13y ago
Ah ha, that's actually not the doing of Slim but rather my usage of I18n, the localisation system used in Rails. Whenever you see t("something.stuff") or I18n.t("something.other.stuff") it's looking for those keys in YAML files under config/locales, primarily in en.yml at the moment. So the text you're looking for is here: https://github.com/afternoonrobot/photographer-io/blob/master/config/locales/en.yml#L102 https://github.com/afternoonrobot/photographer-io/blob/maste...
I'm not sure my way's the best, but I'm passing two generated links into that t() call which are then interpolated into the string in the YAML file.
If you've not used I18n before then it can make the views really confusing to read through without the text to reference! :)
- marcamillion 13y agoAhhh....right. I haven't used it much...but that's an interesting take on it. I've seen it used for date & time localization - not for such heavy copy usage like this. Do you profile the site - with say Rack-Mini-Profiler to see what the performance hit of using I18n like that would be? I don't see it in the Gemfile, but maybe you are using something else to see what the hit of all those choices are on your performance? It seems that it may be an extra tax - even though it is clever and I like it...just curious what the cost is...and would love to know other non-I18n ways to achieve that, with say ERB.
- robotmay 13y agoI must admit that I haven't looked into the speed side of it too much! I suspect it's not too bad as the YAML file is loaded once on initialisation into a hash, which the t() function then retrieves the values from. I'm not sure if that differs when using a database backend. One benefit of using Slim here is that it's a bit faster than ERB/HAML (as you can see in my token biased benchmarks: https://speakerdeck.com/robotmay/a-simple-introduction-to-effective-caching-in-ruby-on-rails?slide=22 https://speakerdeck.com/robotmay/a-simple-introduction-to-ef...) so it probably negates any extra time that might be added by using locales. There's two main reasons I use locales so heavily: 1. I like my views to be small and largely free of logic 2. I'd like to translate the site into other languages, and using locales from the start makes it much simpler!