Skip to content

Instantly share code, notes, and snippets.

@AnatoliyLitinskiy
Last active August 29, 2015 14:27
Show Gist options
  • Save AnatoliyLitinskiy/3343ee82d5ea134dc722 to your computer and use it in GitHub Desktop.
Save AnatoliyLitinskiy/3343ee82d5ea134dc722 to your computer and use it in GitHub Desktop.
Sublime snippet 'i18n' [xml], [python], [js]

i18n Sublime snippet

<snippet>
  <content><![CDATA[
<?php echo __( '${1:${SELECTION/'/\\'/g}}' ) ?>
]]></content>
  <tabTrigger>i18n</tabTrigger>
</snippet>

save code above to file

Data/Packages/User/i18n.sublime-snippet

add shortcut like this

{ "keys": ["ctrl+shift+8"], "command": "insert_snippet", "args": { "name": "Packages/User/i18n.sublime-snippet" } },

new snippets hint

If you want to have more hints while creating new snippets, create new Plugin with following code:

NewSnippetCommand.py

import sublime, sublime_plugin
import os

class NewSnippetCommand(sublime_plugin.WindowCommand):
    def run(self):
        v = self.window.new_file()
        v.settings().set('default_dir',
            os.path.join(sublime.packages_path(), 'User'))
        v.settings().set('default_extension', 'sublime-snippet')
        v.set_syntax_file('Packages/XML/XML.tmLanguage')

        template = """<snippet>
	<content><![CDATA[
${1:Hello, \${1:some default text\} in a \${2:snippet\}.\$3}
]]></content>
	<!-- just cursor positions \$1 and \$2 -->
	<!-- \${1:some default text} -->
	<!-- \${1:\$SELECTION} -->
	<!-- \${1/(.*)/\u\$1/} -->
	<!-- \${1/'/\\\\\\'/g} -->
	<!-- \${1/./=/g} -->
	<!-- \${1:\${SELECTION/'/\\\\\\'/g}} -->
	<!-- \${1/([[:upper:]]+)/(?1_\l\$1:)/g} -->
	<!-- \${1/(.*)/\u\$1/} cannot be empty, \${1:$SELECTION} is required -->
	<!-- max="\${2:50}", maxMessage="\${1:$SELECTION} is too long. It should have {{ \${2:\$2} }}... -->
	<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
	<!-- <tabTrigger>hello</tabTrigger> -->
	<!-- Optional: Set a scope to limit where the snippet will trigger -->
	<!-- <scope>source.python</scope> -->
</snippet>
"""
        v.run_command("insert_snippet", {"contents": template})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment