Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Dec 26, 2023
1 parent 4432e73 commit 8556de0
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 47 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ You can create a new configuration file by using the "Crowdin: Create configurat
"base_path": "folder" // optional
"branch": "master" // optional
"base_url": "https://{organization-name}.crowdin.com" // optional (for Crowdin Enterprise only)
"update_strings": false // optional (for strings based projects)
"cleanup_mode": true // optional (for strings based projects)

"files": [
{
Expand All @@ -107,7 +105,9 @@ You can create a new configuration file by using the "Crowdin: Create configurat
"excluded_target_languages": ["uk", "fr"], // optional
"labels": ["android", "emails"], // optional
"dest": "/app/%file_name%.xml", // optional
"type": "android" // optional
"type": "android", // optional
"update_strings": false, // optional (for strings based projects)
"cleanup_mode": true // optional (for strings based projects)
},
{
"source": "multicolumn.csv",
Expand Down
75 changes: 47 additions & 28 deletions src/client/crowdinClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ export class CrowdinClient {
let finished = false;

while (!finished) {
const status = await this.crowdin.translationsApi.checkBuildStatus(this.projectId, build.data.id);
finished = status.data.status === 'finished';
const statusRes = await this.crowdin.translationsApi.checkBuildStatus(this.projectId, build.data.id);
const status = statusRes.data.status;
if (['failed', 'cancelled'].includes(status)) {
throw new Error(`Build ${status}`);
}
finished = status === 'finished';
}

const downloadLink = await this.crowdin.translationsApi.downloadTranslations(this.projectId, build.data.id);
Expand Down Expand Up @@ -136,12 +140,16 @@ export class CrowdinClient {
let finished = false;

while (!finished) {
const status = await bundlesApi.checkBundleExportStatus(
const statusRes = await bundlesApi.checkBundleExportStatus(
this.projectId,
bundleId,
build.data.identifier
);
finished = status.data.status === 'finished';
const status = statusRes.data.status;
if (['failed', 'cancelled'].includes(status)) {
throw new Error(`Build ${status}`);
}
finished = status === 'finished';
}

const downloadLink = await bundlesApi.downloadBundle(this.projectId, bundleId, build.data.identifier);
Expand Down Expand Up @@ -219,26 +227,30 @@ export class CrowdinClient {

/**
* Uploads file to the Crowdin system. Creates needed folders/branch is they are missing.
*
* @param fsPath full path to file
* @param exportPattern file export pattern
* @param file file path in crowdin system
* @param uploadOption upload option
* @param excludedTargetLanguages excluded target languages
* @param labels labels
* @param scheme import scheme
* @param type file type
*/
async upload(
fsPath: string,
exportPattern: string,
file: string,
uploadOption?: SourceFilesModel.UpdateOption,
excludedTargetLanguages?: string[],
labels?: string[],
scheme?: Scheme,
type?: SourceFilesModel.FileType
): Promise<void> {
async upload({
fsPath,
exportPattern,
file,
uploadOption,
excludedTargetLanguages,
labels,
scheme,
type,
cleanupMode,
updateStrings,
}: {
fsPath: string;
exportPattern: string;
file: string;
uploadOption?: SourceFilesModel.UpdateOption;
excludedTargetLanguages?: string[];
labels?: string[];
scheme?: Scheme;
type?: SourceFilesModel.FileType;
cleanupMode?: boolean;
updateStrings?: boolean;
}): Promise<void> {
let branchId: number | undefined;
const branch = this.crowdinBranch;

Expand Down Expand Up @@ -281,22 +293,29 @@ export class CrowdinClient {
const fileContent = fs.readFileSync(fsPath);

if (this.stringsBased) {
if (!branchId) {
throw new Error('Branch is missing');
}

const resp = await this.crowdin.uploadStorageApi.addStorage(fileName, fileContent);
const build = await this.crowdin.sourceStringsApi.uploadStrings(this.projectId, {
//@ts-ignore
branchId,
storageId: resp.data.id,
cleanupMode: this.config.cleanupMode,
updateStrings: this.config.updateStrings,
cleanupMode,
updateStrings,
});
let finished = false;

while (!finished) {
const status = await this.crowdin.sourceStringsApi.uploadStringsStatus(
const statusRes = await this.crowdin.sourceStringsApi.uploadStringsStatus(
this.projectId,
build.data.identifier
);
finished = status.data.status === 'finished';
const status = statusRes.data.status;
if (['failed', 'cancelled'].includes(status)) {
throw new Error('Failed to upload strings');
}
finished = status === 'finished';
}

return;
Expand Down
2 changes: 0 additions & 2 deletions src/config/configModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export interface ConfigModel {
branch?: string;
basePath?: string;
files: FileModel[];
updateStrings?: boolean;
cleanupMode?: boolean;
}

export function buildClient(docUri: vscode.Uri, config: ConfigModel, stringsBased = false) {
Expand Down
8 changes: 4 additions & 4 deletions src/config/configProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ export class ConfigProvider {
scheme: this.getFileScheme(f.scheme),
dest: f.dest,
type: f.type,
cleanupMode: f.cleanup_mode,
updateStrings: f.update_strings,
} as FileModel;
}),
organization,
cleanupMode: config.cleanup_mode,
updateStrings: config.update_strings,
};
}

Expand Down Expand Up @@ -228,8 +228,6 @@ interface PrivateConfigModel {
base_path?: string;

Check warning on line 228 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `base_path` must match one of the following formats: camelCase

Check warning on line 228 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `base_path` must match one of the following formats: camelCase
base_path_env?: string;

Check warning on line 229 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `base_path_env` must match one of the following formats: camelCase

Check warning on line 229 in src/config/configProvider.ts

View workflow job for this annotation

GitHub Actions / build

Type Property name `base_path_env` must match one of the following formats: camelCase
files: PrivateFileModel[];
update_strings?: boolean;
cleanup_mode?: boolean;
}

interface PrivateFileModel {
Expand All @@ -241,4 +239,6 @@ interface PrivateFileModel {
scheme?: string;
dest?: string;
type?: string;
update_strings?: boolean;
cleanup_mode?: boolean;
}
2 changes: 2 additions & 0 deletions src/config/fileModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface FileModel {
scheme?: Scheme;
dest?: string;
type?: SourceFilesModel.FileType;
cleanupMode?: boolean;
updateStrings?: boolean;
}

export interface Scheme {
Expand Down
22 changes: 12 additions & 10 deletions src/plugin/tree/files/filesTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,18 @@ export class FilesTreeItem extends vscode.TreeItem {
basePath
);
const crowdinFilePath = this.getCrowdinFilePath();
return this.client.upload(
this.fullPath,
exportPattern,
crowdinFilePath,
this.file?.updateOption,
this.file?.excludedTargetLanguages,
this.file?.labels,
this.file?.scheme,
this.file?.type
);
return this.client.upload({
fsPath: this.fullPath,
exportPattern: exportPattern,
file: crowdinFilePath,
uploadOption: this.file?.updateOption,
excludedTargetLanguages: this.file?.excludedTargetLanguages,
labels: this.file?.labels,
scheme: this.file?.scheme,
type: this.file?.type,
cleanupMode: this.file?.cleanupMode,
updateStrings: this.file?.updateStrings,
});
} else {
let promises: Promise<void>[] = [];
for (const item of arr) {
Expand Down

0 comments on commit 8556de0

Please sign in to comment.