Merge pull request #2193 from opf/feature/webpack-i18n-support
Support plugins extending Webpack build pipeline; Build translations from openproject-translationspull/2257/head
commit
b5e3d73b85
@ -1,64 +0,0 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2014 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
# Note: This monkey patch was written to enable configurations like: |
||||
# |
||||
# only: |
||||
# - '*.js' |
||||
# - '*.*.js' |
||||
# - '*.*.*.js' |
||||
# |
||||
# in combination with unevenly nested translations, i.e. |
||||
# en: |
||||
# foo: Foo |
||||
# js: |
||||
# foo: Foo |
||||
# bar: |
||||
# baz: Baz |
||||
# |
||||
# NB: On some levels, there are String _and_ Hash values. |
||||
# |
||||
# The original code only expected to see Hashes, while in the above setup, there |
||||
# might be other values as well. These may be ignored by `filter`, since these |
||||
# values will not contain the relevant translations. |
||||
# |
||||
# At the moment, we are not posting a pull request including the changes to the |
||||
# original author, since s/he is working on a rewrite of i18n-js and s/he does |
||||
# not seem to accept even the simplest pull request. We should try again, when |
||||
# the `rewrite` branch of i18n-js is released to master. |
||||
# |
||||
# Written against i18n-js rewrite branch |
||||
I18n::JS.module_eval do |
||||
class << self |
||||
def filter_with_uneven_nesting_fix(translations, scopes) |
||||
filter_without_uneven_nesting_fix(translations, scopes) if translations.is_a? Hash |
||||
end |
||||
alias_method_chain :filter, :uneven_nesting_fix |
||||
end |
||||
end |
@ -0,0 +1,72 @@ |
||||
//-- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
//++
|
||||
|
||||
/*global exec */ |
||||
/*global test */ |
||||
|
||||
require('shelljs/global'); |
||||
var path = require('path'), |
||||
_ = require('lodash'); |
||||
|
||||
var PLUGIN_INFO_CMD_PATH = path.join(__dirname, '..', 'bin', 'plugin_info'); |
||||
|
||||
function runPluginsInfo() { |
||||
var fullCmd = exec(PLUGIN_INFO_CMD_PATH, { silent: true }); |
||||
return fullCmd.code === 0 ? fullCmd.output : '{}'; |
||||
} |
||||
|
||||
var OpenProjectPlugins = { |
||||
allPluginNamesPaths: _.memoize(function() { |
||||
return JSON.parse(runPluginsInfo()); |
||||
}), |
||||
|
||||
pluginNamesPaths: function() { |
||||
return _.reduce(this.allPluginNamesPaths(), function(obj, pluginPath, pluginName) { |
||||
if (test('-e', path.join(pluginPath, 'package.json'))) { |
||||
obj[pluginName] = pluginPath; |
||||
} else { |
||||
console.info('INFO: plugin "%s" does not provide a package.json', pluginName); |
||||
} |
||||
return obj; |
||||
}, {}); |
||||
}, |
||||
|
||||
findPluginPath: _.memoize(function(name) { |
||||
return this.pluginNamesPaths()[name]; |
||||
}, _.identity), |
||||
|
||||
pluginDirectories: function() { |
||||
return _.reduce(this.allPluginNamesPaths(), function(dirList, pluginPath) { |
||||
var pluginDir = path.dirname(pluginPath); |
||||
return dirList.indexOf(pluginDir) === -1 ? dirList.concat(pluginDir) : dirList; |
||||
}, []); |
||||
} |
||||
}; |
||||
|
||||
exports.pluginNamesPaths = OpenProjectPlugins.pluginNamesPaths(); |
||||
exports.pluginDirectories = OpenProjectPlugins.pluginDirectories(); |
@ -0,0 +1,93 @@ |
||||
<!---- copyright |
||||
OpenProject is a project management system. |
||||
Copyright (C) 2012-2014 the OpenProject Foundation (OPF) |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License version 3. |
||||
|
||||
OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
Copyright (C) 2010-2013 the ChiliProject Team |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; if not, write to the Free Software |
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
See doc/COPYRIGHT.rdoc for more details. |
||||
|
||||
++--> |
||||
|
||||
# Developing OpenProject Plugins |
||||
|
||||
The core functionality of OpenProject may be extended through the use of plugins. |
||||
|
||||
## Rails/backend plugins |
||||
|
||||
Plugins that extend the Rails application are packaged as **Ruby gems**. |
||||
These plugins must contain a `Gem::Specification` (typically as a `.gemspec` |
||||
file in the root directory of the plugin). |
||||
|
||||
**To use a Rails plugin** |
||||
|
||||
* declare the dependency in `Gemfile.plugins` within the `:opf_plugins` group |
||||
using the Bundler DSL. |
||||
|
||||
Example: |
||||
|
||||
```ruby |
||||
group :opf_plugins do |
||||
gem :openproject_costs, git: 'https://github.com/finnlabs/openproject-backlogs.git', branch: 'dev' |
||||
end |
||||
``` |
||||
|
||||
* run `bundle install`. |
||||
|
||||
## Frontend plugins [WIP] |
||||
|
||||
Plugins that extend the frontend application may be packaged as **npm modules**. |
||||
These plugins must contain a `package.json` in the root directory of the plugin. |
||||
|
||||
Plugins are responsible for loading their own assets, including additional |
||||
images, styles and I18n translations. |
||||
|
||||
To load translation strings use the provided `I18n.addTranslation` function: |
||||
|
||||
```js |
||||
I18n.addTranslations('en', require('../../config/locales/js-en.yml').en); |
||||
``` |
||||
|
||||
Pure frontend plugins should be considered _a work in progress_. As such, it is |
||||
currently recommended to create hybrid plugins (see below). |
||||
|
||||
**To use a frontend plugin:** |
||||
|
||||
* You will currently need to modify the `package.json` of OpenProject core |
||||
directly. A more robust solution is currently in planning. |
||||
|
||||
## Hybrid plugins |
||||
|
||||
Plugins that extend both the Rails and frontend applications are possible. They |
||||
must contain both a `Gem::Specification` and `package.json`. |
||||
|
||||
_CAVEAT: npm dependencies for hybrid plugins are not yet resolved._ |
||||
|
||||
**To use a hybrid plugin:** |
||||
|
||||
* declare the dependency in `Gemfile.plugins` within the `:opf_plugins` group |
||||
using the Bundler DSL. |
||||
|
||||
* then run `bundle install`. |
||||
|
||||
You **do not** need to modify the `package.json` of OpenProject core. Provided |
||||
Ruby Bundler is aware of these plugins, Webpack (our node-based build pipeline) |
||||
will bundle their assets. |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue