Coder Social home page Coder Social logo

seb-l / i18n-xlsx-loader Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 5.25 MB

Directly import an XLSX file in your project as source for i18n locales messages.

License: MIT License

JavaScript 7.31% TypeScript 92.69%
i18n webpack loader xslx locales translations

i18n-xlsx-loader's Introduction

i18n-xlsx-loader

Directly import an XLSX file in your project as source for i18n locales messages.

This loader extract the locales messages from an Xlsx file then convert them in javascript exported objects named after the locale name.

Each sheet name is used as root attribute in the final locale js object.

Example:

Sheet Name: common

key fr en
sidebar.hideSidebar Masquer la barre latérale Hide Sidebar

Sheet Name: login

key fr en
form.password Mot de passe Password

will result to:

export const fr = {
  common: {
    sidebar: {
      hideSidebar: 'Masquer la barre latérale'
    }
  },
  login: {
    form: {
      password: 'Mot de passe'
    }
  }
}

export const en = {
  common: {
    sidebar: {
      hideSidebar: 'Hide Sidebar'
    }
  },
  login: {
    form: {
      password: 'Password'
    }
  }
}

Install

yarn add @seb-l/i18n-xlsx-loader -D

or

npm install @seb-l/i18n-xlsx-loader -D

Usage

Update your Webpack configuration

In your webpack.config.js file:

const path = require('path')

{
  ...,
  module: {
    rules: [
      {
        test: path.resolve('locales/translations.xlsx'),
        use: {
          loader: '@seb-l/i18n-xlsx-loader'
        },
      },
    ],
  },
  ...
}

Using with webpack-extend (for a Nuxt app in this example):

const path = require('path')

{
  ...
  extend (config, { isDev, isClient }) {
    config.module.rules.push(
      {
        test: path.resolve('locales/translations.xlsx'),
        loader: '@seb-l/i18n-xlsx-loader',
      }
    )
  }
  ...
}

In the file you want to use your translations in

import { fr, en } from '@/locales/translations.xlsx'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.