All Projects → Fitbit → angular-translate-loader

Fitbit / angular-translate-loader

Licence: Apache-2.0 license
"angular-translate" loader for webpack

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to angular-translate-loader

Stylefmt Loader
Webpack-loader. Fixes stylelint issues automatically while bundling with Webpack.
Stars: ✭ 24 (+60%)
Mutual labels:  loader, webpack-loader
Sass Vars Loader
Use Sass variables defined in Webpack config or in external Javascript or JSON files
Stars: ✭ 112 (+646.67%)
Mutual labels:  loader, webpack-loader
Thread Loader
Runs the following loaders in a worker pool
Stars: ✭ 945 (+6200%)
Mutual labels:  loader, webpack-loader
Css Loader
CSS Loader
Stars: ✭ 4,067 (+27013.33%)
Mutual labels:  loader, webpack-loader
Pug As Jsx Loader
Stars: ✭ 168 (+1020%)
Mutual labels:  loader, webpack-loader
Inject Loader
💉📦 A Webpack loader for injecting code into modules via their dependencies.
Stars: ✭ 474 (+3060%)
Mutual labels:  loader, webpack-loader
Vue Svg Inline Loader
Webpack loader used for inline replacement of SVG images with actual content of SVG files in Vue projects.
Stars: ✭ 105 (+600%)
Mutual labels:  loader, webpack-loader
nunjucks-loader
Webpack loader for Nunjucks templates
Stars: ✭ 20 (+33.33%)
Mutual labels:  loader, webpack-loader
Rust Native Wasm Loader
Stars: ✭ 156 (+940%)
Mutual labels:  loader, webpack-loader
Vue Pretty Logger
The console is more cool to use, easier to debug, and more fun log output. Enjoy the vue-pretty-logger in the vue project.
Stars: ✭ 150 (+900%)
Mutual labels:  loader, webpack-loader
Sass Loader
Compiles Sass to CSS
Stars: ✭ 3,718 (+24686.67%)
Mutual labels:  loader, webpack-loader
jsx-compress-loader
⚛️JSX optimisation loader to reduce size of React application
Stars: ✭ 40 (+166.67%)
Mutual labels:  loader, webpack-loader
Markdown Loader
markdown loader for webpack
Stars: ✭ 335 (+2133.33%)
Mutual labels:  loader, webpack-loader
Wasm Loader
✨ WASM webpack loader
Stars: ✭ 604 (+3926.67%)
Mutual labels:  loader, webpack-loader
typed-css-modules-loader
💠 Webpack loader for typed-css-modules auto-creation
Stars: ✭ 62 (+313.33%)
Mutual labels:  loader, webpack-loader
Svgr
Transform SVGs into React components 🦁
Stars: ✭ 8,263 (+54986.67%)
Mutual labels:  loader, webpack-loader
markup-inline-loader
a webpack loader to embed svg/MathML to html
Stars: ✭ 24 (+60%)
Mutual labels:  loader, webpack-loader
webpack-modernizr-loader
Get your modernizr build bundled with webpack, use modernizr with webpack easily
Stars: ✭ 35 (+133.33%)
Mutual labels:  loader, webpack-loader
Style Loader
Style Loader
Stars: ✭ 1,572 (+10380%)
Mutual labels:  loader, webpack-loader
sizeof-loader
Webpack loader that works like url-loader (or file-loader) but with extracted information such as image dimensions and file-size.
Stars: ✭ 20 (+33.33%)
Mutual labels:  loader, webpack-loader

NPM version Travis build status AppVeyor build status Code Climate Maintainability Code Climate Coverage Dependency Status Development Dependency Status Greenkeeper badge

angular-translate-loader

angular-translate loader for webpack

This loader helps to reduce writing the boilerplate code for angular-translate.

Installation

npm install angular --save && npm install angular-translate-loader --save-dev

or

yarn add angular && yarn add angular-translate-loader --dev

Usage

Instead of writing boilerplate code something like this:

var angular = require("angular");
var translations = angular.module('translations', ['pascalprecht.translate']);

translations.config(function($translateProvider) {
    $translateProvider.translations('en_US', {
        foo: 'bar',
        bar: {
            baz: 'qux'
        }
    });
});

You can do that in single line:

./index.js

var translations = require('!json!angular-translate?module=translations!./index.json');

console.log(translations); // Object { foo: "bar", bar: { baz: "qux" } }

and the loader will do all work for you:

var angular = require("angular");
var translations = {
    foo: "bar",
    bar: {
        baz: "qux"
    }
};
var module;
try {
    module = angular.module("translations");
} catch(err) {
    module = angular.module("translations", ["pascalprecht.translate"]);
}
module.config(["$translateProvider", function($translateProvider) {
    $translateProvider.translations("en_US", translations);
}]);
module.exports = translations;

Also it detects locales in the requested file (please see localeInterpolate option):

./de_DE.json

{
  "foo": "Bar",
  "bar": {
    "baz": "Qux"
  }
}

./index.js

var translations = require('!json!angular-translate?module=translations!./index.json');

console.log(translations); // Object { foo: "Bar", bar: { baz: "Qux" } }
var angular = require("angular");
var translations = {
    foo: "Bar",
    bar: {
        baz: "Qux"
    }
};
var module;
try {
    module = angular.module("translations");
} catch(err) {
    module = angular.module("translations", ["pascalprecht.translate"]);
}
module.config(["$translateProvider", function($translateProvider) {
    $translateProvider.translations("de_DE", translations);
}]);
module.exports = translations;

Also if you want to require all translations at once you can do that as well:

./index.js

var angular = require('angular');

function requireAll(requireContext) {
    return requireContext.keys().map(requireContext);
}

requireAll(require.context('./locales', true, /\.json$/));

angular.module('app', ['translations']);

If you want to add some global options you can do that easily:

./webpack.config.js

module.exports = {
    module: {
        rules: [{
            type: 'javascript/auto',
            test: /\.json$/,
            loader: 'angular-translate-loader',
            options: {
                module: 'translations',
                namespaces: ['app', '[dir]'],
                sep: '.',
                defaultLocale: 'de_DE'
            }
        }]
    }
};

Options

Name Type Default Value Description
module String or String[] 'translations' Sets name of angular module. Supports interpolations and also [dir].
namespaces String or String[] '' Adds namespaces to each translations key. Supports interpolations and also [dir].
sep String '/' Separator for namespaces and module.
localeInterpolate RegExp or RegExp[] or String or String[] [/_[a-z]{2}_[A-Z]{2}\./, /_[a-z]{2}\./, /[/\\][a-z]{2}_[A-Z]{2}[/\\]/, /[/\\][a-z]{2}[/\\]/] Uses to detect locale in resourcePath.
defaultLocale String 'en_US' Uses defaultLocale if localeInterpolate fails to detect it.
requireAngular Boolean true Indicates whether to add var angular = require("angular") to generated code or not. Defaults to true.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].