New tails snippet for I18n.t

Bug #876786 reported by Aldis Berjoza
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
UltiSnips
Fix Released
Undecided
Unassigned

Bug Description

snippet t
I18n.t('`!v substitute(substitute(substitute(@%, substitute(getcwd() . "/", "\/", "\\\\/", "g"), "", ""), "\\(\\.\\(html\\|js\\)\\.\\(haml\\|erb\\)\\|\\(_controller\\)\\?\\.rb\\)$", "", ""), "/", ".", "g")`.${2:${1/[^\w]/_/g}}${3}', :default => "${1:some_text}"${4})${5:$0}
endsnippet

I've developed this snippet for RoR, to translate code.
It use converts filepath to something like "app.controllers.some_controller" and appends ".some_text"
This makes localizing apps using YAML files very easy and fast

This snippet is meant to be used from root of rails project.

Related branches

Revision history for this message
Aldis Berjoza (graudeejs) wrote :

You may rename at it your will

Revision history for this message
SirVer (sirver) wrote :

wow, thissnippet seems like a lot of work to come up with! But i do not understand what it does, nor where it should go to? What is tails? What is RoR? And do you think this is generally useful for a lot of others?

Changed in ultisnips:
status: New → Incomplete
Revision history for this message
Aldis Berjoza (graudeejs) wrote :

RoR = Ruby on Rails
It should be added to rails snippets.

I think that this would be very useful to many Ruby on Rails programmers, who meed to write internationalized sites

It is especially useful, if you fallow methods described in http://guides.rubyonrails.org/i18n.html

No imagine that you need to have "This internationalized text" somewhere in code (let's imagine that we need it in app/views/documents/index.html.haml file)

In my setup, i hit "t" and tab and snippet start working:
I18n.t("app.views.documents.index.some_text", :default => "some_text")
At this moment you have some_text selected... you type in "This internationalized text" and get
I18n.t("app.views.documents.index.This_internationalized_text", :default => "This internationalized text")

Now, in yaml file, where you keep translations, you write
lv:
..app:
....views:
....documents:
......index:
........This_internationalized_text: "Šis internacionalizētais teksts"

Node prefixed dots replresend spaces

With help of this sipped I translated my work a LOT faster

Revision history for this message
Aldis Berjoza (graudeejs) wrote :

ERR: it should be

lv:
 ..app:
 ....views:
 ......documents:
 ........index:
 ..........This_internationalized_text: "Šis internacionalizētais teksts"

Note: lv is locale name

Revision history for this message
Aldis Berjoza (graudeejs) wrote :

If you could wite multiple snippet regex, and multiple line VimL code, I'd write much better snippet.
For now this is best I could come up. (it took me about hour, to figure this snippet)

Revision history for this message
SirVer (sirver) wrote :

merged in r320. Thanks for contributing.

Changed in ultisnips:
status: Incomplete → Fix Committed
Revision history for this message
SirVer (sirver) wrote :

Release in 1.6.

Changed in ultisnips:
milestone: none → 1.6
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Bug attachments