po-loader

raw JSON →
0.7.0 verified Sat Apr 25 auth: no javascript maintenance

Webpack loader for translating .po files (GNU gettext) into JSON. Uses po2json under the hood, supports mozilla/nunjucks, Jed, and other formats. Version 0.7.0 (latest, 2017). Sync and async usage; often paired with Jed for i18n. No updates since 2017, works with webpack v1 only. Not actively maintained; consider @lingui/webpack or i18n-webpack-plugin.

error Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type.
cause No loader configured for .po files in webpack
fix
Add po-loader and json-loader to webpack config: { test: /\.po$/, loader: 'json!po' }
error Cannot find module 'po2json'
cause Missing peer dependency po2json
fix
npm install po2json@>=1.0.0-beta-3 --save-dev or --save
breaking po-loader requires webpack 1.x only; does not work with webpack 2+ modular loaders. Use json!po syntax which breaks in webpack 2+
fix Upgrade to webpack 1 or switch to a modern i18n webpack plugin like @lingui/webpack
deprecated po2json peer dependency must be >=1.0.0-beta-3, but that version may have breaking changes. Always pin exact version.
fix Use po2json@1.0.0-beta-3 exactly in package.json
gotcha Requiring .po files without the json loader prefix (json!po) will output raw po2json format, not run through po-loader
fix Always use json!po prefix in require or configure in webpack.config with json!po loader string
breaking Dynamic import path must match the regex for webpack to create separate bundles; otherwise returns undefined
fix Use import(`${LOCALE_ROOT}/${locale}/LC_MESSAGES/messages.po`) with LOCALE_ROOT as a constant string
npm install po-loader
yarn add po-loader
pnpm add po-loader

Webpack config to load .po files with po-loader and json-loader, then async import a .po file and use Jed.

// webpack.config.js
{
  test: /\.po$/,
  loader: 'json!po',
  exclude: /node_modules/
}

// entry.js
import Jed from 'jed';

async function init() {
  const localeData = await import('./locale/en_US/LC_MESSAGES/messages.po');
  const i18n = new Jed(localeData);
  console.log(i18n.gettext('Hello'));
}

init();