Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit 29e48f2

Browse files
committedJun 8, 2016
Finish up i18n support.
This commit adds the actual loading of textdomain language .mo files, and generating the .pot file.
1 parent 87bf7d2 commit 29e48f2

File tree

5 files changed

+198
-31
lines changed

5 files changed

+198
-31
lines changed
 

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

‎Gruntfile.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = function( grunt ) {
2+
'use strict';
3+
4+
grunt.initConfig( {
5+
makepot: {
6+
options: {
7+
type: 'wp-plugin',
8+
domainPath: '/languages',
9+
potHeaders: {
10+
'report-msgid-bugs-to': 'https://github.com/coderkevin/wp-rest-api-plugin-jquery-example/issues'
11+
}
12+
},
13+
dist: {
14+
options: {
15+
potFilename: 'wp-rest-api-plugin-jquery-example.pot'
16+
}
17+
}
18+
},
19+
} );
20+
21+
grunt.loadNpmTasks( 'grunt-wp-i18n' );
22+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright (C) 2016 Kevin Killingsworth
2+
# This file is distributed under the GPL-3.0+.
3+
msgid ""
4+
msgstr ""
5+
"Project-Id-Version: REST API Plugin - JQuery Example 0.1.0\n"
6+
"Report-Msgid-Bugs-To: "
7+
"https://github.com/coderkevin/wp-rest-api-plugin-jquery-example/issues\n"
8+
"POT-Creation-Date: 2016-06-08 18:18:19+00:00\n"
9+
"MIME-Version: 1.0\n"
10+
"Content-Type: text/plain; charset=utf-8\n"
11+
"Content-Transfer-Encoding: 8bit\n"
12+
"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
13+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14+
"Language-Team: LANGUAGE <LL@li.org>\n"
15+
"X-Generator: grunt-wp-i18n 0.5.4\n"
16+
17+
#: wp-rest-api-plugin-jquery-example.php:66
18+
msgid "REST API Plugin Example Using jQuery"
19+
msgstr ""
20+
21+
#: wp-rest-api-plugin-jquery-example.php:67
22+
msgid "REST API Example"
23+
msgstr ""
24+
25+
#: wp-rest-api-plugin-jquery-example.php:96
26+
msgid "Post"
27+
msgstr ""
28+
29+
#: wp-rest-api-plugin-jquery-example.php:97
30+
msgid "Author"
31+
msgstr ""
32+
33+
#: wp-rest-api-plugin-jquery-example.php:98
34+
msgid "Status"
35+
msgstr ""
36+
37+
#: wp-rest-api-plugin-jquery-example.php:99
38+
msgid "Published"
39+
msgstr ""
40+
41+
#: wp-rest-api-plugin-jquery-example.php:100
42+
msgid "Scheduled"
43+
msgstr ""
44+
45+
#: wp-rest-api-plugin-jquery-example.php:101
46+
msgid "Draft"
47+
msgstr ""
48+
49+
#: wp-rest-api-plugin-jquery-example.php:102
50+
msgid "Pending Review"
51+
msgstr ""
52+
53+
#: wp-rest-api-plugin-jquery-example.php:103
54+
msgid "Private"
55+
msgstr ""
56+
57+
#: wp-rest-api-plugin-jquery-example.php:104
58+
msgid "(loading)"
59+
msgstr ""
60+
61+
#: wp-rest-api-plugin-jquery-example.php:115
62+
msgid "Search Posts:"
63+
msgstr ""
64+
65+
#. Plugin Name of the plugin/theme
66+
msgid "REST API Plugin - JQuery Example"
67+
msgstr ""
68+
69+
#. Plugin URI of the plugin/theme
70+
msgid "https://github.com/coderkevin/wp-rest-api-plugin-jquery-example"
71+
msgstr ""
72+
73+
#. Description of the plugin/theme
74+
msgid "Example code for using the WordPress REST API in a plugin"
75+
msgstr ""
76+
77+
#. Author of the plugin/theme
78+
msgid "Kevin Killingsworth"
79+
msgstr ""
80+
81+
#. Author URI of the plugin/theme
82+
msgid "https://github.com/coderkevin"
83+
msgstr ""

‎package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "wp-rest-api-plugin-jquery-example",
3+
"description": "Example code for WordPress REST API v2 using jQuery in a plugin.",
4+
"version": "1.0.0",
5+
"author": "Kevin Killingsworth (https://github.com/coderkevin)",
6+
"license": "GPL-3.0+",
7+
"homepage": "https://github.com/coderkevin/wp-rest-api-plugin-jquery-example#readme",
8+
"keywords": [
9+
"wordpress",
10+
"rest",
11+
"api",
12+
"jquery"
13+
],
14+
"repository": {
15+
"type": "git",
16+
"url": "git+https://github.com/coderkevin/wp-rest-api-plugin-jquery-example.git"
17+
},
18+
"bugs": {
19+
"url": "https://github.com/coderkevin/wp-rest-api-plugin-jquery-example/issues"
20+
},
21+
"main": "Gruntfile.js",
22+
"scripts": {},
23+
"dependencies": {},
24+
"devDependencies": {
25+
"grunt": "~0.4.5",
26+
"grunt-wp-i18n": "^0.5.4"
27+
}
28+
}

‎wp-rest-api-plugin-jquery-example.php

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,44 @@ class REST_API_Plugin_JQuery_Example {
2929
const TEXT_DOMAIN = 'rest-api-plugin-jquery-example';
3030

3131
public function __construct() {
32-
// Add an Admin Menu for our plugin.
32+
add_action( 'init', array( $this, 'init' ), 0 );
33+
}
34+
35+
/**
36+
* Initialize localization and admin menu.
37+
*/
38+
public function init() {
39+
$this->load_plugin_textdomain();
3340
add_action( 'admin_menu', array( $this, 'attach_menu' ) );
3441
}
3542

43+
/**
44+
* Load Localization files.
45+
*
46+
* Note: first loaded translation overrides following.
47+
*
48+
* This look for:
49+
* WP_LANG_DIR/rest-api-plugin-jquery-example/rest-api-plugin-jquery-example-LOCALE.mo
50+
* WP_LANG_DIR/plugins/rest-api-plugin-jquery-example-LOCALE.mo
51+
*/
52+
public function load_plugin_textdomain() {
53+
$domain = REST_API_Plugin_JQuery_Example::TEXT_DOMAIN;
54+
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
55+
$mo_file = $domain . '-' . get_locale() . '.mo';
56+
57+
load_textdomain( $domain, WP_LANG_DIR . '/' + $domain + '/' . $mo_file );
58+
load_plugin_textdomain( $domain, false, plugin_basename( dirname( __FILE__ ) ) . '/languages/' );
59+
}
60+
61+
/**
62+
* Attaches the admin menu we'll use for our plugin.
63+
*/
3664
public function attach_menu() {
65+
$domain = REST_API_Plugin_JQuery_Example::TEXT_DOMAIN;
66+
3767
add_menu_page(
38-
__( 'REST API Plugin Example Using jQuery', 'rest-api-plugin-jquery-example' ),
39-
__( 'REST API Example', 'rest-api-plugin-jquery-example' ),
68+
__( 'REST API Plugin Example Using jQuery', $domain ),
69+
__( 'REST API Example', $domain ),
4070
'read',
4171
'rest-api-plugin-jquery-example',
4272
array( $this, 'output_page' ),
@@ -45,8 +75,11 @@ public function attach_menu() {
4575
);
4676
}
4777

78+
/**
79+
* Outputs the scripts and html for our page.
80+
*/
4881
public function output_page() {
49-
$text_domain = REST_API_Plugin_JQuery_Example::TEXT_DOMAIN;
82+
$domain = REST_API_Plugin_JQuery_Example::TEXT_DOMAIN;
5083

5184
wp_enqueue_script( 'jquery' );
5285

@@ -62,36 +95,36 @@ public function output_page() {
6295
'api_root' => esc_url_raw( rest_url() ),
6396
'api_nonce' => wp_create_nonce( 'wp_rest' ),
6497
'i18n' => array(
65-
'post' => __( 'Post', $text_domain ),
66-
'author' => __( 'Author', $text_domain ),
67-
'status' => __( 'Status', $text_domain ),
68-
'publish' => __( 'Published', $text_domain ),
69-
'future' => __( 'Scheduled', $text_domain ),
70-
'draft' => __( 'Draft', $text_domain ),
71-
'pending' => __( 'Pending Review', $text_domain ),
72-
'private' => __( 'Private', $text_domain ),
73-
'loading' => __( '(loading)', $text_domain ),
98+
'post' => __( 'Post', $domain ),
99+
'author' => __( 'Author', $domain ),
100+
'status' => __( 'Status', $domain ),
101+
'publish' => __( 'Published', $domain ),
102+
'future' => __( 'Scheduled', $domain ),
103+
'draft' => __( 'Draft', $domain ),
104+
'pending' => __( 'Pending Review', $domain ),
105+
'private' => __( 'Private', $domain ),
106+
'loading' => __( '(loading)', $domain ),
74107
)
75108
) );
76109

77-
?>
78-
<div class="rest-api-example">
79-
<h1>REST API Plugin Example Using jQuery</h1>
80-
<p>This is the example page for using the REST API from a plugin using jQuery!</p>
81-
<div id="post-search">
82-
<form id="search-form" class="search">
83-
<label>
84-
<?php echo __( 'Search Posts:', $text_domain ) ?>
85-
<input id="search-box" type="search"></input>
86-
</label>
87-
<span id="search-message"></span>
88-
</form>
89-
90-
<table id="post-table">
91-
</table>
92-
</div>
93-
</div>
94-
<?php
110+
?>
111+
<div class="rest-api-example">
112+
<h1><?php _e( 'REST API Plugin Example Using jQuery', $domain ) ?></h1>
113+
<p><?php _e( 'This is the example page for using the REST API from a plugin using jQuery!', $domain ) ?></p>
114+
<div id="post-search">
115+
<form id="search-form" class="search">
116+
<label>
117+
<?php _e( 'Search Posts:', $domain ) ?>
118+
<input id="search-box" type="search"></input>
119+
</label>
120+
<span id="search-message"></span>
121+
</form>
122+
123+
<table id="post-table">
124+
</table>
125+
</div>
126+
</div>
127+
<?php
95128
}
96129

97130
}

0 commit comments

Comments
 (0)
This repository has been archived.