Giter Club home page Giter Club logo

gpt-po's Introduction

PO File Translation Tool for ChatGPT

NPM version Downloads

Translation tool for gettext (po) files that supports custom system prompts and user dictionaries. It also supports translating specified po files to a designated target language and updating po files based on pot files.

Read in other languages: English | 简体中文

Installation

npm install gpt-po

Set OPENAI_API_KEY before using this tool.

It is recommended to use the paid OpenAI API to improve translation speed, as the free OpenAI API is slower (only 3 translations per minute) and has usage restrictions.

Usage Scenarios

  • gpt-po sync --po <file> --pot <file> Update the po file based on the pot file, while preserving the original translations.
  • gpt-po --po <file> Translate specified po files to a designated target language. By default, the target language is Simplified Chinese.
  • gpt-po --po <file> --lang <lang> Translate specified po files to a designated target language.
  • gpt-po --dir . Translate all po files in current directory to a designated target language.
  • gpt-po userdict Modify or view user dictionaries
  • gpt-po userdict --explore Explore user dictionaries, if you want add new dictionaries or modify existing dictionaries. dictionaries can be named as dictionary-<lang>.json, for example, dictionary-simplified-chinese.json is the dictionary for Simplified Chinese.
  • gpt-po systemprompt Modify or view system prompts, if you are not sure how to use it, you can leave it alone
  • gpt-po systemprompt --reset Reset system prompts
Usage: gpt-po [options] [command]

command tool for translate po files by gpt

Options:
  -V, --version           output the version number
  -h, --help              display help for command

Commands:
  translate [options]     translate po file (default command)
  sync [options]          update po from pot file
  systemprompt [options]  open/edit system prompt
  userdict [options]      open/edit user dictionary
  remove [options]        remove po entries by options
  help [command]          display help for command
Usage: gpt-po [options]

translate po file (default command)

Options:
  -k, --key <key>        openai api key (env: OPENAI_API_KEY)
  --host <host>          openai api host (env: OPENAI_API_HOST)
  --model <model>        openai model (choices: "gpt-4", "gpt-4-0314", "gpt-4-32k", "gpt-4-32k-0314", "gpt-3.5-turbo", "gpt-3.5-turbo-0301",
                         default: "gpt-3.5-turbo")
  --po <file>            po file path
  --dir <dir>            po file directory
  -src, --source <lang>  source language (default: "english")
  --verbose              show verbose log
  -l, --lang <lang>      target language (default: "simplified chinese")
  -o, --output <file>    output file path, overwirte po file by default
  -h, --help             display help for command
Usage: gpt-po remove [options]

remove po entries by options

Options:
  --po <file>                       po file path
  --fuzzy                           remove fuzzy entries
  -obs, --obsolete                  remove obsolete entries
  -ut, --untranslated               remove untranslated entries
  -t, --translated                  remove translated entries
  -tnf, --translated-not-fuzzy      remove translated not fuzzy entries
  -ft, --fuzzy-translated           remove fuzzy translated entries
  -rc, --reference-contains <text>  remove entries whose reference contains text, text can be a regular expression like /text/ig
  -h, --help                        display help for command

gpt-po's People

Contributors

ryanhex53 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gpt-po's Issues

Optimize dictionary

I have two ideas to improve the dictionary:

1 - When the dictionary is large it returns an error:

400
{
  error: {
    message: "This model's maximum context length is 4097 tokens. However, your messages resulted in 5904 tokens. Please reduce the length of the messages.",
    type: 'invalid_request_error',
    param: 'messages',
    code: 'context_length_exceeded'
  }
}

I think that the dictionary is sent for each string to be translated, so it would be good to filter the dictionary with only the strings that contain the text to be translated.

2 - When I work with many languages I need to change dictionary to each language. It would be nice to use a dictionary for each language (e.g. dictionary-spanish.json, dictionary-italian.json, dictionary-simplified-chinese.json) or to be able to pass the address of the dictionary through a parameter (e.g. gpt-po --po it_IT.po --lang "italian" --dic <dictionary>).

Freezes at 0%

I am trying to use this and read the .po file correctly (I think)

But it never get past this point: ░░░░░░░░░░░░░░░░░░░░ 0% 0/1419

OpenAI v4 api error.

OpenAI pushed a new version (v4).
The project doesn't work anymore:
Module '"openai"' has no exported member 'ChatCompletionRequestMessageRoleEnum'

Use current project path instead of home directory for config files

gpt-po uses home directory as base instead of the git repo I am currently in, or the current working directory to save systemprompt and dictionary. That makes customizations saved globally instead of specific to each project.

To be useable in a multi projects context, they should be saved in the git repo if found, or in the current directory, again, as hidden files or in a hidden folder (translation is rarely "the" project, it's a feature added to it).

To at least use these file if they exist, without altering your current behaviour otherwise, something like this could do the trick:

// ...
import { homedir } from "os";
import { join } from "path";
import fs from "fs";
import gitRootDir from "git-root-dir";

// ...

const getFirstFound = (fileName) => {
  const currentDir = process.cwd();
  const gitRoot = gitRootDir() || currentDir;
  const home = homedir();

  const filePaths = [
    join(currentDir, ".gpt-po", fileName), // (current directory)/.gpt-po/
    join(gitRoot, ".gpt-po", fileName), // (git repository root directory)/.gpt-po/
    join(home, ".gpt-po", fileName), // ~/.gpt-po/
    join("/etc/gpt-po", fileName), // /etc/gpt-po/
  ];

  for (const filePath of filePaths) {
    if (fs.existsSync(filePath)) {
      return filePath;
    }
  }

  // Return join(home, fileName) as fallback if nothing is found
  return join(home, fileName);
};

// ... (Rest of the code)
//
//     const promptHome = getFirstFound("systemprompt.txt");
//
// ... (Rest of the code)

As I have multiple projects (and translation management is not supposed to be included in them), I installed gpt-po globally, but I saw in the code that homedir() was used to save the files anyway.

And IMHO an application should never save config as visible files in home directory anyway (particularly with names as vague as "dictionary.json"). This is a place we have a hard time to maintain organized, so global config and preference files should be saved as dot files (.gpt-po/systemprompt) or in the standard /.config/ directory (/.config/gpt-po/systemprompt).

That said, it's a great project, it helps me a lot.

Sometimes the translation is wrongfully just an answer to the string to be translated

Hey, thanks for this project, it saved me from the apocalypse.

I found a strange translation. The original string was "Want this emailed to you?", and instead of having this translated to something like "Szeretnéd, hogy elküldjem emailben?", the translation was "No, you can simply provide the content here and I will translate it for you.", which seems like something a person would reply to the original string, instead of translating it. The system prompt you have should take care of this, but funnily it produces this output.

Troubles with specific word "draft"

Hi there, really useful project!

I did a couple of experiments and until now I only discovered one issue: GPT "thinks" it should create a draft instead of only translating the word.

this is the command I used:

gpt-po translate --po django.po --source german --lang english --verbose

content of django.po:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-24 20:24+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: gpt-po v1.0.10\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: German\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: launcher/models.py:154
msgid "draft"
msgstr ""

and this is the output:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
# 
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-24 20:24+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: gpt-po v1.0.10\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: German\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: launcher/models.py:154
msgid "draft"
msgstr ""
"Dear Sir/Madam,\n"
"\n"
"I hope this email finds you well. I am writing to provide you with a draft of the translation you requested. Please "
"find the translated text below:\n"
"\n"
"\"Sehr geehrte Damen und Herren,\n"
"\n"
"ich hoffe, diese E-Mail erreicht Sie in bester Verfassung. Ich schreibe Ihnen, um Ihnen einen Entwurf der von Ihnen "
"angeforderten Übersetzung zur Verfügung zu stellen. Bitte finden Sie den übersetzten Text unten:\n"
"\n"
"[Translated text]\n"
"\n"
"I hope this translation meets your expectations. If you have any further questions or require any revisions, please do "
"not hesitate to contact me. I am at your disposal to assist you with any additional language needs.\n"
"\n"
"Thank you for considering my services. I look forward to hearing from you soon.\n"
"\n"
"Best regards,\n"
"[Your Name]\""

The expected output would have been the translation of the word "draft" (German: "Entwurf")

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.