-
-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to import libraries on top of the translations file in an es6 way #549
Conversation
I currently use https://github.com/usabilityhub/rails-erb-loader: // i18n-js.js.erb or i18n-js-ts.erb
<%# encoding: UTF-8 %>
// Optional dependency watching
// Tell webpack to watch these files
// https://github.com/usabilityhub/rails-erb-loader#dependencies
/* rails-erb-loader-dependencies ./../config/locales/ */
import I18n from "i18n-js"
I18n.translations = <%= I18n::JS.filtered_translations.to_json %>;
export default I18n My erb loader file: module.exports = {
test: /\.erb$/,
enforce: "pre",
exclude: /node_modules/,
use: [{
loader: "rails-erb-loader",
options: {
runner: (/^win/.test(process.platform) ? "ruby " : "") + "bin/rails runner",
env: {
...process.env,
DISABLE_SPRING: 1,
RAILS_CONFIG_EAGER_LOAD_ENABLED_IN_DEVELOPMENT: "false",
},
},
}],
} |
I really like your solution @PikachuEXE , but you need an extra package and change the options file in webpacker, what do you think about the solution I offer in this PR? The new option in the yml file is completely optional. |
LGTM |
Still pending change from @mcamara though |
@PikachuEXE done :) |
Travis tests have failedHey @mcamara, Ruby: 2.5rake
TravisBuddy Request Identifier: 638af320-ea73-11e9-90a0-7556777797a6 |
Hey @mcamara, TravisBuddy Request Identifier: 67b502e0-ea75-11e9-90a0-7556777797a6 |
Hey @mcamara, TravisBuddy Request Identifier: 6a66dc70-ea75-11e9-90a0-7556777797a6 |
Hey @mcamara, TravisBuddy Request Identifier: 89671c20-ea75-11e9-90a0-7556777797a6 |
Hey @mcamara, TravisBuddy Request Identifier: 916e50f0-ea75-11e9-90a0-7556777797a6 |
Hey @mcamara, TravisBuddy Request Identifier: 923ceb90-ea75-11e9-90a0-7556777797a6 |
Hey @mcamara, TravisBuddy Request Identifier: 98175550-ea75-11e9-90a0-7556777797a6 |
Hey @mcamara, TravisBuddy Request Identifier: 990c8ac0-ea75-11e9-90a0-7556777797a6 |
Hey @mcamara, TravisBuddy Request Identifier: c0a73e90-ea75-11e9-90a0-7556777797a6 |
Hey @mcamara, TravisBuddy Request Identifier: c18df510-ea75-11e9-90a0-7556777797a6 |
Hey @mcamara, TravisBuddy Request Identifier: c6ad4c30-ea75-11e9-90a0-7556777797a6 |
Hey @mcamara, TravisBuddy Request Identifier: d96f8b30-ea75-11e9-90a0-7556777797a6 |
Thanks |
Released in |
@@ -248,6 +248,27 @@ MyNamespace.translations["en"] = { ... } | |||
``` | |||
|
|||
|
|||
### Adding a line at the beggining of the translations file (useful for imports) | |||
|
|||
Setting the `prefix: "import I18n from 'i18n-js';\n"` option will add the line at the beggining of the resultant translation file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: beginning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 64d8c5a
In order to use rails with webpack and the i18n-js npm package all together,
import I18n from 'i18n-js';
should be added to the resultanttranslations.js
file.This PR allows an user to add the import programatically just adding the option in the
i18n-js.yml
file.Thanks @PikachuEXE for your package, I hope you find this option useful 😄