
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
= i18n_screwdriver
Translating applications is often a pain in the ass. The problem with rails i18n is that you have to use keys for every string to translate. That is one too many abstraction layers - I love the gettext syntax but I want to stick to the rails standard libraries. Therefor I created this small toolbox.
== Installation
Just include the screwdriver gem in your Bundler Gemfile
gem 'i18n_screwdriver'
Then run the generator that copies the translation rake task to your application task dir.
rails g screwdriver
== Usage
Set these constants to make i18n screwdriver aware of the languages you are using
I18n.default_locale I18n.available_locales
In your views, helpers and controllers use the convenient underscore helper method for all your translations
_("your translation")
Starting with version 6.0 you can also use symbols as keys
_(:my_long_text)
Starting with version 7.0 we added namespaces. A translation in the form of _("User|Name") will use the full string as a key but only display the part after the pipe, so "Name". This is useful if you want to have text translated differently according to the context in some languages but have it the same in the source language. For example "User|Name" (in German "Benutzername") and "Account|Name" (in German "Accountname").
Variable interpolation works as for normal strings
_("Hello %{name}!") % {name: "Liah"}
For awesome support for links inside translations you can use this syntax, which uses the normal rails view/ route helpers internally
_("Please <> for more details or visit <> to continue."){ [@item, "http://continue.com"] } _("Open this <> in new window or visit <> to continue."){ [[@item, target: "_blank"], "http://continue.com"] }
When you are done you have 2 helper rake tasks. The first one scans all your views, controllers and helpers for translations. It removes unused translation strings and creates an application..yml file for each of your I18n.available_locales.
rake i18n:update
The second one lets you translate your application..yml file line by line. Of course you can edit the application..yml file itself - but dont do that for your default language file. It gets recreated everytime you run the tasks - edit those translations in your views e.g. itself.
TRANSLATE=en rake i18n:translate
=== Node Package
Requires {i18n-js}[https://www.npmjs.com/package/i18n-js] as a peer dependency.
First install the npm-package
yarn add i18n-screwdriver
And then configure I18n with the i18n-screwdriver plugin
import I18n from "i18n-js" import configure from "i18n-screwdriver"
configure(I18n)
I18n.screw("Your translations")
== Test Helpers
In your tests (functionals and integration) you can use the same translation helper
_("your translation")
== Next steps
also recognize model validation error messages
DRY the code
test more (= test at all)
use ruby_parser instead of regex
support interpolation like the following (take care about naming - could be different in other languages)
_("my name is %{name} and I am living in %{location}", :name => @name, :location => @location)
== Contributing to i18n_screwdriver
== Copyright
Copyright (c) 2010 - 2021 Tobias Miesel & {Corin Langosch}[http://www.corinlangosch.com]. Released unter the MIT license.
FAQs
Unknown package
We found that i18n_screwdriver demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.