Skip to content

Commit

Permalink
[COOK-3321] Add languages recipe
Browse files Browse the repository at this point in the history
Signed-off-by: Seth Vargo <[email protected]>
  • Loading branch information
koseki authored and sethvargo committed Sep 18, 2013
1 parent 3b0c42b commit 8c0e3a8
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 7 deletions.
66 changes: 62 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ If a different version than the default is desired, download that version and ge

Attributes
----------
`node['wordpress']` attributes:

<table>
<thead>
<tr>
Expand Down Expand Up @@ -78,6 +80,28 @@ Attributes
<td><tt>/nfs/wp</tt></td>
<td><tt>/var/www</tt></td>
</tr>
<tr>
<td>server_aliases</td>
<td>server aliases for Apache</td>
<td><tt>['foo.com']</tt></td>
<td><tt>[(node's FQDN)]</tt></td>
</tr>
</tbody>
</table>

`node['wordpress']['db']` attributes:

<table>
<thead>
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Example</th>
<th>Default</th>
</tr>
</thead>

<tbody>
<tr>
<td>database</td>
<td>name of the database to use</td>
Expand All @@ -96,11 +120,45 @@ Attributes
<td><tt>P@s$w0rD</tt></td>
<td><tt>(randomly generated)</tt></td>
</tr>
</tbody>
</table>

`node['wordpress']['languages']` attributes:

<table>
<thead>
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Example</th>
<th>Default</th>
</tr>
</thead>

<tbody>
<tr>
<td>server_aliases</td>
<td>server aliases for Apache</td>
<td><tt>['foo.com']</tt></td>
<td><tt>[(node's FQDN)]</tt></td>
<td>lang</td>
<td>WPLANG value</td>
<td><tt>ja</tt></td>
<td><tt>''</tt></td>
</tr>
<tr>
<td>version</td>
<td>version of the <a href="http://translate.wordpress.org/projects/wp">WordPress translation projects</a></td>
<td><tt>3.6.x</tt></td>
<td><tt>''</tt></td>
</tr>
<tr>
<td>projects</td>
<td>translation project names to install</td>
<td><tt>['main']</tt></td>
<td><tt>['main', 'admin', 'admin_network', 'continents_cities']</tt></td>
</tr>
<tr>
<td>themes</td>
<td>theme translation project names to install</td>
<td><tt>['twentytwelve']</tt></td>
<td><tt>[]</tt></td>
</tr>
</tbody>
</table>
Expand Down
26 changes: 25 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#
# Author:: Barry Steinglass (<[email protected]>)
# Author:: Koseki Kengo (<[email protected]>)
# Cookbook Name:: wordpress
# Attributes:: wordpress
#
# Copyright 2009-2010, Opscode, Inc.
# Copyright 2009-2013, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -26,3 +27,26 @@
default['wordpress']['db']['database'] = "wordpressdb"
default['wordpress']['db']['user'] = "wordpressuser"
default['wordpress']['server_aliases'] = [node['fqdn']]

# Languages
default['wordpress']['languages']['lang'] = ''
default['wordpress']['languages']['version'] = ''
default['wordpress']['languages']['repourl'] = 'http://translate.wordpress.org/projects/wp'
default['wordpress']['languages']['projects'] = ['main', 'admin', 'admin_network', 'continents_cities']
default['wordpress']['languages']['themes'] = []
default['wordpress']['languages']['project_pathes'] = {
'main' => '/',
'admin' => '/admin/',
'admin_network' => '/admin/network/',
'continents_cities' => '/cc/'
}
%w{ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty}.each do |year|
default['wordpress']['languages']['project_pathes']["twenty#{year}"] = "/twenty#{year}/"
end
node['wordpress']['languages']['project_pathes'].each do |project,project_path|
# http://translate.wordpress.org/projects/wp/3.5.x/admin/network/ja/default/export-translations?format=mo
default['wordpress']['languages']['urls'][project] =
node['wordpress']['languages']['repourl'] + '/' +
node['wordpress']['languages']['version'] + project_path +
node['wordpress']['languages']['lang'] + '/default/export-translations?format=mo'
end
17 changes: 17 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
version "1.1.2"

recipe "WordPress", "Installs and configures WordPress LAMP stack on a single system"
recipe "WordPress::languages", "Install WordPress translation files"

%w{ php openssl }.each do |cb|
depends cb
Expand Down Expand Up @@ -74,3 +75,19 @@
:display_name => "WordPress Server Aliases",
:description => "WordPress Server Aliases",
:default => "FQDN"

attribute "WordPress/languages/lang",
:display_name => "WordPress WPLANG configulation value",
:description => "WordPress WPLANG configulation value",
:default => ""

attribute "WordPress/languages/version",
:display_name => "Version of WordPress translation file",
:description => "Version of WordPress translation file",
:default => ""

attribute "WordPress/languages/projects",
:display_name => "WordPress translation projects",
:description => "WordPress translation projects",
:type => "array",
:default => ["main", "admin", "admin/network", "cc"]
3 changes: 2 additions & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@
:auth_key => node['wordpress']['keys']['auth'],
:secure_auth_key => node['wordpress']['keys']['secure_auth'],
:logged_in_key => node['wordpress']['keys']['logged_in'],
:nonce_key => node['wordpress']['keys']['nonce']
:nonce_key => node['wordpress']['keys']['nonce'],
:lang => node['wordpress']['languages']['lang']
)
notifies :write, "log[wordpress_install_message]"
end
Expand Down
64 changes: 64 additions & 0 deletions recipes/languages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# Cookbook Name:: wordpress
# Recipe:: languages
# Author:: Koseki Kengo <[email protected]>
#
# Copyright 2013, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe "wordpress"

directory "#{node['wordpress']['dir']}/wp-content/languages" do
owner "root"
group "root"
mode "0755"
action :create
recursive true
end

unless node['wordpress']['languages']['lang'].to_s.empty? &&
node['wordpress']['languages']['version'].to_s.empty?
urls = node['wordpress']['languages']['urls']
node['wordpress']['languages']['projects'].to_a.each do |project|
next unless urls[project]

file = "#{node['wordpress']['dir']}/wp-content/languages/"
file += "#{project.tr('_', '-')}-" if project != 'main'
file += "#{node['wordpress']['languages']['lang']}.mo"

remote_file file do
source urls[project]
owner "root"
group "root"
mode "0644"
action :create_if_missing
end
end

node['wordpress']['languages']['themes'].to_a.each do |project|
next unless urls[project]

file = "#{node['wordpress']['dir']}/wp-content/themes/#{project}/languages/"
file += "#{node['wordpress']['languages']['lang']}.mo"

remote_file file do
source urls[project]
owner "root"
group "root"
mode "0644"
action :create_if_missing
end
end
end
2 changes: 1 addition & 1 deletion templates/default/wp-config.php.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ $table_prefix = 'wp_';
* de.mo to wp-content/languages and set WPLANG to 'de' to enable German
* language support.
*/
define ('WPLANG', '');
define ('WPLANG', '<%= @lang %>');

/* That's all, stop editing! Happy blogging. */

Expand Down

0 comments on commit 8c0e3a8

Please sign in to comment.