Skip to content

Commit

Permalink
Don't load translations from xliffsDir during a convert (#73)
Browse files Browse the repository at this point in the history
* Don't load translations from xliffsDir during a convert

- we need a Project instance in order to do a convert
- when the project instance was created, it attempts to
  load translations from the xliffsDir. However, now
  that translation loading from the xliffsDir happens
  recursively, the new Project attempted to load every
  xliff file in the xliffsDir directory (default: ".")
  which was waaaaay too big
- now we pass in a flag to the project constructor that
  turns off loading of translations for a project that
  is only needed for convert.

* Add a changeset
  • Loading branch information
ehoogerbeets authored Mar 3, 2025
1 parent 45991a9 commit 5e58323
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
15 changes: 15 additions & 0 deletions .changeset/lovely-peaches-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"loctool": patch
---

- Fixed a problem where the project that convert needs to
instantiate in order to run tried to find and load every
single xliff file in the current directory recursively as
translations file in the xliffDir. The problem comes in
if there are many xliff files in the current directory
or there are many directories underneath the current
working directory. That caused start-up to take a really
long time.
- The fix is to for the convert action to turn off
loading translation files when instantiating a project.
They are not needed anyways.
54 changes: 30 additions & 24 deletions packages/loctool/lib/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,16 @@ var Project = function(options, root, settings) {
this.paths = new Queue();
this.files = new Queue();

this.db = new LocalRepository({
sourceLocale: this.sourceLocale,
pseudoLocale: this.pseudoLocale,
pathName: ((this.settings.xliffVersion !== 2) ? (path.join(this.xliffsDir[0], this.options.id + ".xliff")): undefined),
project: this,
xliffsDir: this.xliffsDir,
intermediateFormat: this.settings.intermediateFormat
});
if (!settings || typeof(settings.loadTranslations) !== 'boolean' || settings.loadTranslations) {
this.db = new LocalRepository({
sourceLocale: this.sourceLocale,
pseudoLocale: this.pseudoLocale,
pathName: ((this.settings.xliffVersion !== 2) ? (path.join(this.xliffsDir[0], this.options.id + ".xliff")): undefined),
project: this,
xliffsDir: this.xliffsDir,
intermediateFormat: this.settings.intermediateFormat
});
}

logger.debug("New Project: " + this.root + " source: " + this.sourceLocale + ", pseudo: " + this.pseudoLocale);
};
Expand Down Expand Up @@ -255,26 +257,30 @@ Project.prototype.init = function(cb) {
});
this.extensionMap = extensionMap;

this.db.init(function() {
// use the specified locales if they exist, or else use whatever locales
// already exist in the translations. Make sure to also add in the
// pseudo-locale.
this.db.getLocales(this.options.id, undefined, function(dbLocales) {
var locales = this.defaultLocales || dbLocales || [];
if (!this.defaultLocales && !this.settings.nopseudo) {
locales = locales.concat(Object.keys(this.pseudoLocales));
}
if (this.db) {
this.db.init(function() {
// use the specified locales if they exist, or else use whatever locales
// already exist in the translations. Make sure to also add in the
// pseudo-locale.
this.db.getLocales(this.options.id, undefined, function(dbLocales) {
var locales = this.defaultLocales || dbLocales || [];
if (!this.defaultLocales && !this.settings.nopseudo) {
locales = locales.concat(Object.keys(this.pseudoLocales));
}

// weed out the source locales -> don't have to translate to those!
locales = locales.filter(function(locale) {
return locale !== "en" && locale !== this.sourceLocale;
}.bind(this));
// weed out the source locales -> don't have to translate to those!
locales = locales.filter(function(locale) {
return locale !== "en" && locale !== this.sourceLocale;
}.bind(this));

this.locales = locales;
this.locales = locales;

cb();
cb();
}.bind(this));
}.bind(this));
}.bind(this));
} else {
cb();
}
}.bind(this));
};

Expand Down
3 changes: 3 additions & 0 deletions packages/loctool/lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ var TMX = require("./TMX.js");
var logger = log4js.getLogger("loctool.lib.convert");

function convert(settings) {
// don't need to load all the translations because we are just converting
// some files and need a project to do it
settings.loadTranslations = false;
var project = ProjectFactory(".", settings);
if (!project) project = new CustomProject({
name: settings.id,
Expand Down

0 comments on commit 5e58323

Please sign in to comment.