Coder Social home page Coder Social logo

siananda / wp-localize Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eoigal/wp-localize

0.0 1.0 0.0 152 KB

Sublime Text plugin that localizes a selected string using the WordPress i18n translation methods

JavaScript 9.20% Python 90.80%

wp-localize's Introduction

wp-localize

Sublime Text plugin that localizes a selected string using the WordPress i18n translation methods.

This plugin will parse a string of selected text and work out what i18n method to encase the string in.

The plugin has one main assumption; if the selected text is encased in single or double quotes, its assumed the string is used in php code and as such we don't want to echo or print the string

Also, this plugin does not handle every i18n method, just the following most common methods;

  • __()
  • _e()
  • esc_html__()
  • esc_html_e()
  • esc_attr__()
  • esc_attr_e()

Not supported

  • _n() Plurals
  • _x() Context

Typical Uses

Normal text

Follow the yellow brick road
<!-- ctrl + shift + d to localize string -->
<?php _e( 'Follow the yellow brick road' , 'some-text-domain' ); ?>
<!-- ctrl + shift + e to html escape -->
<?php esc_html_e( 'Follow the yellow brick road' , 'some-text-domain' ); ?>
<!-- ctrl + shift + a to attribute escape -->
<?php esc_html_attr( 'Follow the yellow brick road' , 'some-text-domain' ); ?>

Normal text surrounded with QUOTES

'Follow the yellow brick road'
<!-- ctrl + shift + d to localize string -->
__( 'Follow the yellow brick road' , 'some-text-domain' )
<!-- ctrl + shift + e to html escape -->
esc_html__( 'Follow the yellow brick road' , 'some-text-domain' )
<!-- ctrl + shift + d to attribute escape -->
esc_attr__( 'Follow the yellow brick road' , 'some-text-domain' )

Text with URLs and Numbers

I'd like 19,876.23 <a href="http://dictionary.com">words</a> in 100 to <a href="#type=sentence">5,000 sentences</a>
<!-- ctrl + shift + d to localize string -->
<?php printf( __( 'I\'d like %1$s <a href="%2$s">words</a> in %3$d to <a href="%4$s">%5$s sentences</a>' , 'some-text-domain' ), number_format_i18n('19876.23'), 'http://dictionary.com', 100, '#type=sentence', number_format_i18n('5000') ); ?>
<!-- ctrl + shift + e to html escape -->
<?php printf( esc_html__( 'I\'d like %1$s <a href="%2$s">words</a> in %3$d to <a href="%4$s">%5$s sentences</a>' , 'some-text-domain' ), number_format_i18n('19876.23'), 'http://dictionary.com', 100, '#type=sentence', number_format_i18n('5000') ); ?>
<!-- ctrl + shift + a to attribute escape -->
<?php printf( esc_attr__( 'I\'d like %1$s <a href="%2$s">words</a> in %3$d to <a href="%4$s">%5$s sentences</a>' , 'some-text-domain' ), number_format_i18n('19876.23'), 'http://dictionary.com', 100, '#type=sentence', number_format_i18n('5000') ); ?>

Text with URLs and Numbers surrounded with QUOTES

'I'd like 19,876.23 <a href="http://dictionary.com">words</a> in 100 to <a href="#type=sentence">5,000 sentences</a>'
<!-- ctrl + shift + d to localize string -->
sprintf( __( 'I\'d like %1$s <a href="%2$s">words</a> in %3$d to <a href="%4$s">%5$s sentences</a>' , 'some-text-domain' ), number_format_i18n('19876.23'), 'http://dictionary.com', 100, '#type=sentence', number_format_i18n('5000') )
<!-- ctrl + shift + e to html escape -->
sprintf( esc_html__( 'I\'d like %1$s <a href="%2$s">words</a> in %3$d to <a href="%4$s">%5$s sentences</a>' , 'some-text-domain' ), number_format_i18n('19876.23'), 'http://dictionary.com', 100, '#type=sentence', number_format_i18n('5000') )
<!-- ctrl + shift + d to attribute escape -->
sprintf( esc_attr__( 'I\'d like %1$s <a href="%2$s">words</a> in %3$d to <a href="%4$s">%5$s sentences</a>' , 'some-text-domain' ), number_format_i18n('19876.23'), 'http://dictionary.com', 100, '#type=sentence', number_format_i18n('5000') )

Setup

* Copy the plugin folder to your Sublime Text Packages folder * Copy the key bindings to the Sublime Text Default Key Bindings - User * Update the text domain to whatever slug your theme/plugin uses - leave blank to not include text domain argument in i18n methods

wp-localize's People

Contributors

eoigal avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.