Skip to content

Commit

Permalink
[ilib-loctool-json] Add support for "localizable: key" keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
Natalia Kędziora committed Mar 6, 2025
1 parent 148d019 commit 62b4279
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/ilib-loctool-json/JsonFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ JsonFile.prototype.handleSource = function (json, ref, translations, locale, ret
var opts = {
resType: "string",
project: this.project.getProjectId(),
key: key,
key: this.key ?? key,
sourceLocale: this.project.sourceLocale,
pathName: this.pathName,
state: "new",
Expand All @@ -421,8 +421,6 @@ JsonFile.prototype.handleSource = function (json, ref, translations, locale, ret
}

JsonFile.prototype.extractFromPrimitive = function (localizable, json, ref, translations, locale, returnValue, type) {
console.log({localizable})

switch (localizable) {
case true:
case "source":
Expand All @@ -444,6 +442,7 @@ JsonFile.prototype.extractFromPrimitive = function (localizable, json, ref, tran
}

JsonFile.prototype.parseObj = function (json, root, schema, ref, name, localizable, translations, locale) {
console.log(11111, localizable)
if (!json || !schema) return;

if (this.type.hasType(schema)) {
Expand All @@ -456,7 +455,11 @@ JsonFile.prototype.parseObj = function (json, root, schema, ref, name, localizab
// in the tree
if (!schema) return this.sparseValue(json);

const prevLoc = localizable;
localizable = localizable || schema.localizable
console.log(22222, localizable)
console.log(33333, prevLoc)

var type = schema.type || typeof (json);
switch (type) {
case "boolean":
Expand All @@ -473,6 +476,12 @@ JsonFile.prototype.parseObj = function (json, root, schema, ref, name, localizab
break;

case "object":
if(localizable === "key") {
this.key = ref.startsWith("#/") ? JsonFile.unescapeRef(ref).substring(2) : ref;
console.log(11111)
localizable = prevLoc;
}

if (typeof (json) !== "object") {
this.logger.warn(this.pathName + '/' + ref + " is a " +
typeof (json) + " but should be an object according to the schema... skipping.");
Expand Down

0 comments on commit 62b4279

Please sign in to comment.