1.3.11 β€’ Published 4 months ago

@sheet-i18n/exporter v1.3.11

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

@sheet-i18n/exporter

npm package View changelog

A core logic library for exporting data using the Google Sheets API. This package is designed to simplify the interaction with Google Sheets for i18n and translation workflows.

import { googleSheetExporter } from 'sheet-i18n/exporter';

const exporter = await googleSheetExporter({
  credentials: {
    sheetId: 'your-google-sheet-id',
    clientEmail: 'your-client-email',
    privateKey: 'your-private-key',
  },
  defaultLocale: 'default-language-in-sheet-header',
});

await exporter.exportTranslations();

Configuration βš™οΈ

The configuration object required for using the exporter is as follows:

Required πŸ“

  • credentials: Google Sheets API credentials:
    • sheetId: The ID of your Google Spreadsheet (extracted from the URL).
    • clientEmail: The email of the Google Sheets API client.
    • privateKey: The private key associated with the client.
  • defaultLocale: The default locale/language specified in your Google Sheet header.

Optional πŸ”§

  • headerStartRowNumber: Specifies the row number where the headers begin (if not at the top).
  • ignoredSheets: A list of sheets to exclude by title. By default, sheets without the defaultLocale in headers will be ignored.
  • exportPath: Path to save exported translations. This is the location where the exported translations will be saved. By default, it will use the current working directory (cwd). This option is only used when calling the exportTranslations method.

Exporter Methods πŸ› οΈ

getTranslations πŸ“

  • Description: This function retrieves the translation data, which is structured by locale keys (such as "ko", "en", etc.). It collects all translations from the specified sheet, replaces any placeholders, and prepares them to be sent to the client in the response body. Each key corresponds to a language, and the value for each key is an object containing the translated text for that locale.

  • Type: Function

  • Parameters: None
  • Returns: An object where each key is a locale (e.g., "ko", "en"), and the value is the respective translation data for that locale.

Example:

If the headers in your Google Sheets are ["ko", "en", ...], the result returned by getTranslations will look like this:

{
  "ko": {
    "greeting": "μ•ˆλ…•ν•˜μ„Έμš”",
    "farewell": "μ•ˆλ…•νžˆ κ°€μ„Έμš”"
  },
  "en": {
    "greeting": "Hello",
    "farewell": "Goodbye"
  }

  ...
}

In this example:

  • "ko" contains the translations for Korean.
  • "en" contains the translations for English. Each locale’s object contains key-value pairs for individual translations.

exportTranslations πŸ“€

  • Description: This asynchronous function is used in a Node.js environment to export translations directly into your project. It is especially useful if your project includes server-side APIs (like Next.js API routes) and you need to update the locale JSON data in your project. It can be invoked to update or create the locale files within your project, ensuring that the translation data is synced with the local environment.

  • Type: Function

  • Parameters: None
  • Returns: void

Example:

If you call the exportTranslations function, it will update or create JSON files in your project for each locale. The result could look like this:

// ko.json
{
  "greeting": "μ•ˆλ…•ν•˜μ„Έμš”",
  "farewell": "μ•ˆλ…•νžˆ κ°€μ„Έμš”"
}

// en.json
{
  "greeting": "Hello",
  "farewell": "Goodbye"
}

API Documentation πŸ“š

This package provides a streamlined way to export data using sheets API. It is designed to simplify the integration of spreadsheet data into your applications, particularly for translation workflows and internationalization (i18n).

Google Sheets API Documentation Google Auth Library Google Spreadsheet

Exporting Data Format πŸ—‚οΈ

The exported translations will be saved in a format that is easy to use for localization purposes. Each translation is stored in its respective locale folder, with a structured format.

1.3.11

4 months ago

1.3.10

5 months ago

1.3.9

5 months ago

1.3.8

5 months ago

1.3.7

5 months ago

1.3.6

5 months ago

1.3.5

6 months ago

1.3.4

6 months ago

1.3.3

6 months ago

1.3.2

6 months ago

1.3.1

6 months ago

1.2.0

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.0.0

7 months ago

0.3.0-canary.1

7 months ago

0.2.3-canary.1

7 months ago

0.2.3-canary.0

7 months ago

0.2.2

7 months ago

0.2.2-canary.3

7 months ago

0.2.2-canary.2

7 months ago

0.2.2-canary.1

7 months ago

0.2.2-canary.0

7 months ago

0.2.1

7 months ago

0.2.0

7 months ago

0.1.4

7 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago