mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-13 19:01:21 +00:00
* Add orca-translations Claude skill and PO tool
Add a .claude skill that guides translation passes over the localization/i18n gettext catalogs. It covers the workflow: run gettext, settle new glossary terms, translate in batches, verify, and report.
Includes translation-rules.md, which condenses the placeholder, line-break and glossary rules plus the guidance on review notes.
Also adds scripts/po_tool.py (standard library only). It lists pending entries with glossary hints, validates and applies translations, adding '# AI Translated' and '# Needs human review' comments, and rewrites only the entries it changes. It can also check catalogs, look up existing translations, suggest glossary candidates and update the wiki glossary TSV.
* Let po_tool apply translations by entry id
pending now gives each entry a short id, so a translation file can name
entries by id instead of repeating the English msgid. apply accepts either.
A "review": "" item clears an earlier review note when overwriting an
entry, and check gives each msgfmt run its own temporary output file so
parallel checks do not collide.
* Fill all empty translations
Regenerate the template with run_gettext --full and translate every empty
entry in the 22 catalogs (7,089 entries) with the orca-translations skill,
following the localization glossary, including the new belt printer,
IDEX/IQEX and plugin terms. Every new entry is marked "# AI Translated";
122 also carry "# Needs human review" with what to check.
* Show entry ids in po_tool lookup and search translations
lookup now prints each entry's id, so an entry found there can be
rewritten with apply --overwrite without repeating the English, and
--msgstr searches the translations instead of the msgids, which finds
every entry that still uses a term being changed.
SKILL.md describes how to change an established term: check the
catalog's usage first, update the glossary cell, then rewrite only the
entries where the term has that meaning.
* Fix mistranslated terms and align catalogs with the glossary
Correct labels that the glossary had copied, and the entries that used
them:
- ca: Raft was rendered as the Brim term; it is now "Rai". Exhaust fan,
Monotonic line, Unretract, Slice, Lateral Honeycomb and PA Tower
labels fixed.
- cs: Lightning infill is "Blesk", not "Osvětlení" (illumination).
- sv: Retraction is "Retraktion", not "Reduktion"; Unretract,
Lagerhöjd, Delkylningsfläkt, Utsugsfläkt, Aligned Rectilinear and the
Preset label fixed.
- de: Brim is "Rand" and Skirt is "Umrandung", as most entries already
had them.
- lt: brim entries used the Skirt word "apvadas"; they now use "kraštas".
- es: Sparse infill is "relleno de baja densidad", the catalog majority.
- eu: nozzle wipe is "garbiketa", not purge.
- th: the project plate is "เพลต", distinct from the bed.
- uk: Quarter Cubic, Latin "PA" in PA Tower, and Belt purge tower.
- pl: Cross Hatch, Tri-hexagon, Volumetric speed and Raft labels.
- zh_TW: Brim stays "Brim", as the existing labels have it.
- tr: "Prime Tower" read "Prime Minister Tower".
- ko: the plugin "Capabilities" label read "performance".
- Build Volume labels fixed in tr, de, cs and eu.
All 242 rewritten entries are marked "# AI Translated".
* Make more UI text translatable and fix pluralization and context
Audit the sources for text that translators could not translate
correctly and fix it.
Mark text that reached users in English only: IDEX/IQEX role names,
plugin permission prompts and errors, 3MF/preset loading errors, G-code
placeholder parser errors, calibration and device messages, notification
texts, file dialog filters, and the config validation messages.
Replace sentences built from translated fragments, such as the prime
tower warnings, "left"/"right" nozzle names, and "Filament " + number,
with single msgids that have placeholders, so translators can reorder
and inflect them.
Use plural forms for texts with a count ("%1% mixed filaments",
"%d objects", "%1% triangles") instead of "(s)" and mismatched verbs.
Fix the swapped singular/plural pair in "The following presets inherit
this preset".
Add translation contexts where one English word has several meanings
(Subscribed/Local, Standard, Pause, View, Step, Model, Camera, Flow,
Filter, Others, Prepare, the Design tools). Show "Size" instead of
"Build Volume" in the Cut tool, which displays the object size.
Fix code that compared translated text with English (the Edit G-code
dialog group, the plugin registration failure check), and add the
bundled web pages' missing string-table entries. Use the single
character for degrees Celsius, say "G-code", and describe the head
filament map without internal jargon.
Install the libslic3r translate callback before the presets load, so
their load errors are translated, and list the 28 source files that had
marked strings but were never extracted into localization/i18n/list.txt.
* Suggest earlier translations and list fuzzy entries in po_tool pending
pending now attaches the closest earlier translation of a similar
English text (from obsolete or translated entries), so a reworded or
split string keeps its wording, and it lists fuzzy entries by default,
since users never see them. A fuzzy entry also carries its stale
translation as previous_translation.
* Fix wording of the non-boolean operands error
The logical operation error said "operators" where it means the
operands the operation was applied to.
* Translate the newly translatable strings in all languages
Regenerate the template after the translatability changes and fill every
new or changed entry in the 22 catalogs (about 12,800 entries): the
strings that became translatable, the plural forms, the entries split by
context, and the previously fuzzy singular entries that became plurals.
Every new entry is marked "# AI Translated", and about 360 also carry a
"# Needs human review" note saying what to check. Terms follow the
localization glossary. Earlier translations of reworded strings were
reused where the meaning was unchanged. Existing entries were not
changed, and obsolete entries are kept.
* Document the source translatability audit in the orca-translations skill
Add a reference describing how strings reach translators, what to look
for (untranslated text, spliced sentences, missing plurals, ambiguous
words), what not to translate, where a context cannot be carried, and
what to do after the edits, plus a scanner that lists untranslated
user-facing string literals.
* Document how to write translatable strings in AGENTS.md
Tell developers to keep each message complete in one msgid: use
placeholders instead of concatenating translated fragments, plural forms
for counts, and contexts for ambiguous words, and to list new source
files in localization/i18n/list.txt. Add a matching code review item.
* Translate the strings added since the rebase
Regenerate the template against the current main and translate the 26
new entries per language: the Fix Model commands and messages, and the
texture displacement image adjustment panel. Each new entry is marked
"# AI Translated"; existing entries are unchanged.
* tidy
270 lines
9.0 KiB
C++
270 lines
9.0 KiB
C++
#include <cstddef>
|
|
#include <cstdio>
|
|
#include <boost/filesystem/path.hpp>
|
|
#include <boost/filesystem/operations.hpp>
|
|
#include <boost/filesystem/file_status.hpp>
|
|
#include <exception>
|
|
#include <cstdint>
|
|
|
|
#include "miniz_extension.hpp"
|
|
#include "Utils.hpp"
|
|
|
|
#include <boost/filesystem.hpp>
|
|
#include <boost/log/trivial.hpp>
|
|
#include <string>
|
|
#include <miniz.h>
|
|
#include <stdio.h>
|
|
|
|
#if defined(_MSC_VER) || defined(__MINGW64__)
|
|
#include "boost/nowide/cstdio.hpp"
|
|
#endif
|
|
|
|
#include "I18N.hpp"
|
|
|
|
//! macro used to mark string used at localization,
|
|
//! return same string
|
|
#define L(s) Slic3r::I18N::translate(s)
|
|
|
|
namespace Slic3r {
|
|
|
|
namespace {
|
|
std::string decode_zip_unicode_path_extra_field(const std::string& extra, const std::string& path)
|
|
{
|
|
size_t offset = 0;
|
|
const mz_uint32 path_crc = mz_crc32(0, reinterpret_cast<const unsigned char*>(path.data()), path.size());
|
|
|
|
while (offset + 4 <= extra.size()) {
|
|
const unsigned char* field = reinterpret_cast<const unsigned char*>(extra.data() + offset);
|
|
const std::uint16_t len = field[2] | (static_cast<std::uint16_t>(field[3]) << 8);
|
|
if (offset + 4 + len > extra.size())
|
|
break;
|
|
|
|
if (field[0] == 0x75 && field[1] == 0x70 && len >= 5 && field[4] == 0x01) {
|
|
const mz_uint32 stored_crc =
|
|
static_cast<mz_uint32>(field[5]) |
|
|
(static_cast<mz_uint32>(field[6]) << 8) |
|
|
(static_cast<mz_uint32>(field[7]) << 16) |
|
|
(static_cast<mz_uint32>(field[8]) << 24);
|
|
if (stored_crc == path_crc)
|
|
return std::string(extra.data() + offset + 9, extra.data() + offset + 4 + len);
|
|
}
|
|
|
|
offset += 4 + len;
|
|
}
|
|
|
|
return Slic3r::decode_path(path.c_str());
|
|
}
|
|
|
|
bool open_zip(mz_zip_archive *zip, const char *fname, bool isread)
|
|
{
|
|
if (!zip) return false;
|
|
const char *mode = isread ? "rb" : "wb";
|
|
|
|
FILE *f = nullptr;
|
|
#if defined(_MSC_VER) || defined(__MINGW64__)
|
|
f = boost::nowide::fopen(fname, mode);
|
|
#elif defined(__GNUC__) && defined(_LARGEFILE64_SOURCE)
|
|
f = fopen64(fname, mode);
|
|
#else
|
|
f = fopen(fname, mode);
|
|
#endif
|
|
|
|
if (!f) {
|
|
zip->m_last_error = MZ_ZIP_FILE_OPEN_FAILED;
|
|
return false;
|
|
}
|
|
|
|
bool res = false;
|
|
if (isread)
|
|
{
|
|
res = mz_zip_reader_init_cfile(zip, f, 0, 0);
|
|
if (!res)
|
|
// if we get here it means we tried to open a non-zip file
|
|
// we need to close the file here because the call to mz_zip_get_cfile() made into close_zip() returns a null pointer
|
|
// see: https://github.com/prusa3d/PrusaSlicer/issues/3536
|
|
fclose(f);
|
|
}
|
|
else
|
|
res = mz_zip_writer_init_cfile(zip, f, 0);
|
|
|
|
return res;
|
|
}
|
|
|
|
bool close_zip(mz_zip_archive *zip, bool isread)
|
|
{
|
|
bool ret = false;
|
|
if (zip) {
|
|
FILE *f = mz_zip_get_cfile(zip);
|
|
ret = bool(isread ? mz_zip_reader_end(zip)
|
|
: mz_zip_writer_end(zip));
|
|
if (f) fclose(f);
|
|
}
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
bool open_zip_reader(mz_zip_archive *zip, const std::string &fname)
|
|
{
|
|
return open_zip(zip, fname.c_str(), true);
|
|
}
|
|
|
|
bool open_zip_writer(mz_zip_archive *zip, const std::string &fname)
|
|
{
|
|
return open_zip(zip, fname.c_str(), false);
|
|
}
|
|
|
|
bool close_zip_reader(mz_zip_archive *zip) { return close_zip(zip, true); }
|
|
bool close_zip_writer(mz_zip_archive *zip) { return close_zip(zip, false); }
|
|
|
|
std::string decode_archive_entry_path(mz_zip_archive *zip, const mz_zip_archive_file_stat &stat)
|
|
{
|
|
if (stat.m_is_utf8)
|
|
return stat.m_filename;
|
|
|
|
std::string extra(1024, 0);
|
|
const size_t extra_size = mz_zip_reader_get_extra(zip, stat.m_file_index, extra.data(), extra.size());
|
|
return decode_zip_unicode_path_extra_field(extra.substr(0, extra_size > 0 ? extra_size - 1 : 0), stat.m_filename);
|
|
}
|
|
|
|
bool extract_archive_confined(const std::string &zip_path_utf8, const std::string &dest_dir)
|
|
{
|
|
mz_zip_archive archive;
|
|
mz_zip_zero_struct(&archive);
|
|
|
|
if (!open_zip_reader(&archive, zip_path_utf8)) {
|
|
BOOST_LOG_TRIVIAL(error) << "Unable to open zip reader for " << zip_path_utf8;
|
|
return false;
|
|
}
|
|
|
|
const mz_uint num_entries = mz_zip_reader_get_num_files(&archive);
|
|
mz_zip_archive_file_stat stat;
|
|
|
|
// Validate every entry first so an archive with a single escaping entry leaves no partial output behind.
|
|
const boost::filesystem::path root(dest_dir);
|
|
for (mz_uint i = 0; i < num_entries; ++i) {
|
|
if (mz_zip_reader_file_stat(&archive, i, &stat) && !is_path_within_root(stat.m_filename, root)) {
|
|
BOOST_LOG_TRIVIAL(error) << "Unzip: rejecting " << zip_path_utf8 << ", entry " << stat.m_filename << " resolves outside " << dest_dir;
|
|
close_zip_reader(&archive);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
for (mz_uint i = 0; i < num_entries; ++i) {
|
|
if (!mz_zip_reader_file_stat(&archive, i, &stat)) {
|
|
BOOST_LOG_TRIVIAL(warning) << "Unzip: read file stat failed";
|
|
continue;
|
|
}
|
|
const std::string dest_file = dest_dir + "/" + stat.m_filename;
|
|
try {
|
|
if (stat.m_is_directory) {
|
|
const boost::filesystem::path dest_path(dest_file);
|
|
if (!boost::filesystem::exists(dest_path))
|
|
boost::filesystem::create_directories(dest_path);
|
|
continue;
|
|
}
|
|
if (stat.m_uncomp_size == 0) {
|
|
BOOST_LOG_TRIVIAL(warning) << "Unzip: invalid size for file " << stat.m_filename;
|
|
continue;
|
|
}
|
|
// Replace a symlink at the destination rather than writing through it.
|
|
const boost::filesystem::path dest_path(dest_file);
|
|
if (boost::filesystem::is_symlink(boost::filesystem::symlink_status(dest_path)))
|
|
boost::filesystem::remove(dest_path);
|
|
if (!mz_zip_reader_extract_to_file(&archive, stat.m_file_index, dest_file.c_str(), 0)) {
|
|
BOOST_LOG_TRIVIAL(error) << "Unzip: extract file " << stat.m_filename << " to dest " << dest_file << " failed";
|
|
close_zip_reader(&archive);
|
|
return false;
|
|
}
|
|
BOOST_LOG_TRIVIAL(info) << "Unzip: successfully extract file " << stat.m_file_index << " to " << dest_file;
|
|
} catch (const std::exception &e) {
|
|
close_zip_reader(&archive);
|
|
BOOST_LOG_TRIVIAL(error) << "Unzip: archive read exception: " << e.what();
|
|
return false;
|
|
}
|
|
}
|
|
close_zip_reader(&archive);
|
|
return true;
|
|
}
|
|
|
|
MZ_Archive::MZ_Archive()
|
|
{
|
|
mz_zip_zero_struct(&arch);
|
|
}
|
|
|
|
std::string MZ_Archive::get_errorstr(mz_zip_error mz_err)
|
|
{
|
|
switch (mz_err)
|
|
{
|
|
case MZ_ZIP_NO_ERROR:
|
|
return "no error";
|
|
case MZ_ZIP_UNDEFINED_ERROR:
|
|
return L("undefined error");
|
|
case MZ_ZIP_TOO_MANY_FILES:
|
|
return L("too many files");
|
|
case MZ_ZIP_FILE_TOO_LARGE:
|
|
return L("File too large");
|
|
case MZ_ZIP_UNSUPPORTED_METHOD:
|
|
return L("unsupported method");
|
|
case MZ_ZIP_UNSUPPORTED_ENCRYPTION:
|
|
return L("unsupported encryption");
|
|
case MZ_ZIP_UNSUPPORTED_FEATURE:
|
|
return L("unsupported feature");
|
|
case MZ_ZIP_FAILED_FINDING_CENTRAL_DIR:
|
|
return L("failed finding central directory");
|
|
case MZ_ZIP_NOT_AN_ARCHIVE:
|
|
return L("not a ZIP archive");
|
|
case MZ_ZIP_INVALID_HEADER_OR_CORRUPTED:
|
|
return L("invalid header or corrupted");
|
|
case MZ_ZIP_UNSUPPORTED_MULTIDISK:
|
|
return L("Saving to RAID is not supported.");
|
|
case MZ_ZIP_DECOMPRESSION_FAILED:
|
|
return L("decompression failed");
|
|
case MZ_ZIP_COMPRESSION_FAILED:
|
|
return L("compression failed");
|
|
case MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE:
|
|
return L("unexpected decompressed size");
|
|
case MZ_ZIP_CRC_CHECK_FAILED:
|
|
return L("CRC check failed");
|
|
case MZ_ZIP_UNSUPPORTED_CDIR_SIZE:
|
|
return L("unsupported central directory size");
|
|
case MZ_ZIP_ALLOC_FAILED:
|
|
return L("allocation failed");
|
|
case MZ_ZIP_FILE_OPEN_FAILED:
|
|
return L("file open failed");
|
|
case MZ_ZIP_FILE_CREATE_FAILED:
|
|
return L("file create failed");
|
|
case MZ_ZIP_FILE_WRITE_FAILED:
|
|
return L("file write failed");
|
|
case MZ_ZIP_FILE_READ_FAILED:
|
|
return L("file read failed");
|
|
case MZ_ZIP_FILE_CLOSE_FAILED:
|
|
return L("file close failed");
|
|
case MZ_ZIP_FILE_SEEK_FAILED:
|
|
return L("file seek failed");
|
|
case MZ_ZIP_FILE_STAT_FAILED:
|
|
return L("file stat failed");
|
|
case MZ_ZIP_INVALID_PARAMETER:
|
|
return L("invalid parameter");
|
|
case MZ_ZIP_INVALID_FILENAME:
|
|
return L("invalid filename");
|
|
case MZ_ZIP_BUF_TOO_SMALL:
|
|
return L("Buffer too small");
|
|
case MZ_ZIP_INTERNAL_ERROR:
|
|
return L("internal error");
|
|
case MZ_ZIP_FILE_NOT_FOUND:
|
|
return L("file not found");
|
|
case MZ_ZIP_ARCHIVE_TOO_LARGE:
|
|
return L("Archive too large");
|
|
case MZ_ZIP_VALIDATION_FAILED:
|
|
return L("validation failed");
|
|
case MZ_ZIP_WRITE_CALLBACK_FAILED:
|
|
return L("write callback failed");
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return L("unknown error");
|
|
}
|
|
|
|
} // namespace Slic3r
|