0.8.103 • Published 7 months ago

@enterprise_search/translation v0.8.103

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Translation Software

This package provides a framework for handling multi-language translations in projects. It supports loading and saving translation files in both JSON and CSV formats, validating configuration, and checking mismatches between translations.


Installation

npm install "@enterprise_search/translation"

Or if you want it from the command line

npm install -g "@enterprise_search/indexer"

From the command line

This requires a config file in the name

npm install -g "@enterprise_search/indexer"

index experiment translation-init         # Createsan example translation.yaml file. 
                                          # Gives instructions on where files should be placed

index experiment translation              # Turns csv files into json files
index experiment translation --invert     # Turns json files into csv files
index experiment translation --help       # For more information 

Features

  • Converts a csv file with langauges for columns into json suitable for i18n
  • Can 'invert' the process to convert json files into csv files. This is useful if you have existing json files you want to consolidate and manage better
  • Error Handling: Returns validation and processing errors, while 'doing as much as it can'
  • Mismatch detection: checks for mismatchs across languages... places where something is defined in one language but not in another.

Important Files and Modules

config/config.ts

Holds the type definitions for the core entities:

  • TranslationConfig: Describes the configuration for translations.
  • CsvFilesDescription and JsonFilesDescription: Define the source and target file structures.
  • Contains helper methods:
  • validateTranslationConfig(config: TranslationConfig): Validates the configuration.
  • invertTranslationConfig(config: TranslationConfig): Switches the source and target for reverse operations.

translate.ts

Core functions for performing translations:

  • translateAllLanguageFiles: Translates all specified files in a configuration.
  • _translateOneLanguageFile: Translates a single file, returning any errors or mismatches.

loaders and savers

  • loadCsvLanguageFile: Loads translations from CSV files.
  • saveCsvLanguageFile: Saves translations to CSV files.
  • loadJsonLanguageFiles: Loads translations from JSON files.
  • saveJsonLanguageFile: Saves translations to JSON files.

Example Usage

Sample Configuration: by default in a file called translation.yaml

source: # This is the source of truth for the language files
  type: csv
  directory: sample.translation/csv/{file}.csv  # Note the {file} placeholder. Change this to your directory structure.
  pathFieldName: path

target: # This is where we put the generated language files.
  type: json
  directory: sample.translation/json/{file}/{language}.json # Note the {file} and {language} placeholders. Change this to your directory structure.

languages: # This is the list of languages we want to generate
  - de
  - en

languageFiles: # And for each language, we want to generate these files
  - about-us
  - room-booking
  - translation```

Translation Workflow

async function runTranslation(config: TranslationConfig) {
  // Validate configuration
  const validate = defaultTranslationOperations.validateTranslationConfig(config);

  if (hasErrors(validate)) {
    console.error('Configuration errors:', validate);
    return;
  }

  // Perform translations
  try {
    const errors = await translateAllLanguageFiles(defaultTranslationOperations, config);
    if (errors.length) {
      console.error('Translation errors:', errors);
    } else {
      console.log('Translations completed successfully!');
    }
  } catch (error) {
    console.error('Unexpected error:', error.message);
  }
}

runTranslation(config);

License

MIT License. See the LICENSE.md file for more details.

ChatGPT session

This is the session where we wrote the software. https://chatgpt.com/share/674b0a46-f4e4-8013-9869-4ccd016a0209

0.8.103

7 months ago

0.8.102

7 months ago

0.8.101

7 months ago

0.8.100

7 months ago

0.8.99

7 months ago

0.8.98

7 months ago

0.8.97

7 months ago

0.8.96

7 months ago

0.8.95

7 months ago

0.8.94

8 months ago

0.8.93

8 months ago

0.8.92

8 months ago

0.8.91

8 months ago

0.8.90

8 months ago

0.8.89

8 months ago

0.8.88

8 months ago

0.8.87

8 months ago

0.8.86

8 months ago

0.8.85

8 months ago

0.8.84

9 months ago

0.8.83

9 months ago

0.8.81

10 months ago

0.8.80

10 months ago

0.8.79

11 months ago

0.8.78

11 months ago

0.8.77

11 months ago

0.8.76

11 months ago

0.8.75

11 months ago

0.8.74

12 months ago

0.8.73

12 months ago

0.8.72

12 months ago

0.8.71

12 months ago

0.8.70

12 months ago

0.8.69

12 months ago

0.8.68

12 months ago

0.8.67

12 months ago

0.8.66

12 months ago

0.8.65

1 year ago

0.8.62

1 year ago

0.8.61

1 year ago

0.8.60

1 year ago

0.8.58

1 year ago

0.8.57

1 year ago

0.8.56

1 year ago

0.8.55

1 year ago

0.8.54

1 year ago

0.8.53

1 year ago

0.8.52

1 year ago

0.8.51

1 year ago

0.8.50

1 year ago

0.8.49

1 year ago

0.8.48

1 year ago

0.8.47

1 year ago