Socket
Book a DemoInstallSign in
Socket

i18n-po-sheet-sync

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18n-po-sheet-sync

A Node.js library that facilitates synchronization between multilingual PO files and Google Spreadsheets.

latest
Source
npmnpm
Version
2.0.1
Version published
Maintainers
1
Created
Source

i18n-po-sheet-sync

English | 한국어

A Node.js library that facilitates synchronization between multilingual PO files and Google Spreadsheets.
Paid collaborative tools are often used for efficient multilingual management.
However, in most cases, paid tools can be a financial burden. Therefore, Google Spreadsheets alone are usually sufficient.

The .PO extension is widely used in internationalization and localization (i18n) systems for multilingual programs. i18n-po-sheet-sync enables quick and simple multilingual management through synchronization between .PO files and Google Spreadsheets.

Features

  • Export multilingual data from Google Spreadsheets to PO files
  • Upload multilingual data from PO files to Google Spreadsheets
  • Support for two upload methods (incremental update / batch update after sheet reset)
  • Synchronize context, references, and comments of multilingual items
  • Automatically apply conditional formatting to empty translation cells
  • TypeScript support
  • Usage with Other Multilingual Frameworks (lingui, i18next)

Example

  • Please refer to the example folder for usage instructions of i18n-po-sheet-sync.
  • The locales folder contains PO files organized by language (en, ko, etc.).
  • example-account-auth.json is an example of service account credentials with access permissions to Google Spreadsheet. Please change it to your own service account credentials when using.
  • To view an example Google Spreadsheet managed by i18n-po-sheet-sync, click here.

Installation

npm install i18n-po-sheet-sync
# or
yarn add i18n-po-sheet-sync

Usage

Basic Configuration

import I18nPOSheetSync from 'i18n-po-sheet-sync';
import { join } from 'path';

// Configuration
const config = {
  serviceAccount: {
    email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
    key: process.env.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY,
  },
  spreadsheetId: 'GOOGLE_SHEET_ID',
  languages: ['ko', 'en', 'ja', 'zh', '...'],
  poFilesBasePath: join(__dirname, 'locale/locales')
};

// Create instance
const i18nSync = new I18nPOSheetSync(config);

Export from Google Spreadsheet to PO files

async function exportToPO() {
  try {
    const results = await i18nSync.exportToPO({
      filterMissingTranslations: false,
      preserveExistingItems: true
    });
    
    console.log('Export completed:', results);
  } catch (error) {
    console.error('Export failed:', error);
  }
}

exportToPO();

Upload from PO files to Google Spreadsheet

async function uploadFromPO() {
  try {
    const result = await i18nSync.uploadFromPO({
      applyConditionalFormatting: true, // Apply background color to empty cells
      emptyColor: '#FFEBEE', // Empty cell background color (light red)
      preserveExistingTranslations: true, // Preserve existing translations
    });
    
    console.log('Upload from po completed:', result);
  } catch (error) {
    console.error('Upload failed:', error);
  }
}

uploadFromPO();

Apply Conditional Formatting Only

async function applyFormatting() {
  try {
    await i18nSync.applyConditionalFormatting('#FFEBEE');
    console.log('Conditional formatting applied successfully');
  } catch (error) {
    console.error('Failed to apply formatting:', error);
  }
}

applyFormatting();

Configuration Options

Basic Configuration (I18nSyncConfig)

OptionTypeDescription
serviceAccountServiceAccountConfigGoogle service account information
languagesstring[]Array of supported language codes
poFilesBasePathstringBase path where PO files are stored
sheetIndexnumber (optional)Sheet index within the spreadsheet (default: 0)

Spreadsheet Header Titles

OptionTypeDescription
msgidstringMessage ID header (default: 'messageId')
msgctxtstring (optional)Context header (default: 'context')
referencesstring (optional)References header (default: 'references')
commentsstring (optional)Comments header (default: 'comments')
extractedCommentsstring (optional)Extracted comments header (default: 'extractedComments')

Export Options (ExportOptions)

OptionTypeDefaultDescription
filterMissingTranslationsbooleanfalseWhether to filter items with missing translations
preserveExistingItemsbooleanfalseWhether to preserve existing PO items not in the spreadsheet
pluralFormsByLanguageRecord<string, string>-Specify plural rules by language

Upload Options (UploadOptions)

OptionTypeDefaultDescription
applyConditionalFormattingbooleanfalseWhether to apply background color to empty translation cells
emptyColorstring#FFEBEEBackground color for empty translation cells (HEX code)
preserveExistingTranslationsbooleanfalseWhether to preserve existing translation values

Google Spreadsheet Format

The library expects a spreadsheet in the following format:

messageIdkoen...contextreferencescommentsextractedComments
hello안녕하세요Hello...greetingsrc/App.jsGreetingUser greeting
goodbye안녕히 가세요Goodbye...greetingsrc/App.jsFarewellOn logout

Header names can be changed through the HeaderMapping option.

Usage with Other Multilingual Frameworks

Using with lingui

  • Can be used together with lingui, an i18n multilingual framework.
yarn add --dev @lingui/cli
  • Add to package.json
{
  "scripts": {
    "extract": "lingui extract",
    "compile": "lingui compile",
    "upload": "ts-node scripts/upload-translate.ts",
    "export": "ts-node scripts/export-translate.ts",
  }
}
  • Running the extract script generates .PO files currently in use.
  • Running the upload script reflects changes to the Google Spreadsheet.
  • Running the export script applies multilingual changes from the Google Spreadsheet.
  • Running the compile script compiles the updated .PO multilingual files.

i18next

i18next-conv -l en -s ./locales/en.translation.json -t ./locales/en/translation.po

License

MIT

Keywords

i18n

FAQs

Package last updated on 19 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts