Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: branch option #46

Merged
merged 6 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions assets/texts.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
},
"info": {
"loadingProjects": "Loading projects",
"loadingBranches": "Loading branches",
"loadingLanguages": "Loading list of languages",
"loadingFiles": "Loading list of files",
"loadingStrings": "Loading strings",
"projectSaved": "Project saved",
"branchSaved": "Branch saved",
"overrideTranslationsSaved": "Override translations flag updated",
"contentSegmentationSaved": "Content segmentation flag updated",
"stringsKeyNamingSaved": "Key naming pattern option updated",
Expand Down Expand Up @@ -57,15 +59,18 @@
"settingsTab": "Settings",
"contactUsTab": "Contact Us",
"selectProjectLabel": "Select Project:",
"selectBranchLabel": "Branch:",
"overrideTranslationsLabel": "Override existing translations",
"contentSegmentationLabel": "Content segmentation",
"stringsKeyNamingLabel": "Key naming pattern:",
"connectionDetailsLabel": "Crowdin Credentials",
"advancedSettingsLabel": "Advanced Settings",
"tokenLabel": "Personal Access Token:",
"tokenDetailsText": "You can generate it in your Crowdin Account Settings",
"overrideTranslationsText": "Override existing translated pages and artboards and keep only the latest version for each language",
"contentSegmentationText": "Defines whether to split long texts into smaller text segments when sending texts to Crowdin",
"stringsKeyNamingText": "Pattern which will be used to autocomplete string identifier if it was added from design",
"branchText": "Specify the branch for content synchronization. Work on branches to localize different product versions",
"organizationLabel": "Organization",
"organizationDetailsText": "Fill in your organization domain name (for Crowdin Enterprise only)",
"connectToCrowdinButton": "Connect to Crowdin",
Expand Down Expand Up @@ -93,7 +98,8 @@
"uploadTranslationsForPageButtonLabel": "Page",
"uploadTranslationsForArtboardButtonLabel": "Artboard",
"loadingDialog": "Loading...",
"allLanguagesOption": "All Languages"
"allLanguagesOption": "All Languages",
"noBranchOption": "Not specified"
},
"details": {
"translationsDetails": "Generate multi-language creative assets like banners or social media graphics. Send designs for translation and upload translated copies back.",
Expand All @@ -108,4 +114,4 @@
"addStringEmptyFile": "Select the source file to add the new string to"
}
}
}
}
9 changes: 6 additions & 3 deletions src/action/send-strings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ui from 'sketch/ui';
import dom from 'sketch/dom';
import settings from 'sketch/settings';
import { PROJECT_ID, ACCESS_TOKEN_KEY, CONTENT_SEGMENTATION } from '../constants';
import { PROJECT_ID, ACCESS_TOKEN_KEY, CONTENT_SEGMENTATION, BRANCH_ID } from '../constants';
import * as domUtil from '../util/dom';
import * as httpUtil from '../util/http';
import * as localStorage from '../util/local-storage';
Expand Down Expand Up @@ -55,15 +55,18 @@ async function sendStrings(wholePage) {

async function uploadStrings(page, artboard) {
const projectId = settings.documentSettingForKey(dom.getSelectedDocument(), PROJECT_ID);
let branchId = settings.documentSettingForKey(dom.getSelectedDocument(), BRANCH_ID);
branchId = !!branchId && branchId > 0 ? branchId : undefined;
const { sourceFilesApi, uploadStorageApi } = httpUtil.createClient();

const directories = await sourceFilesApi.withFetchAll().listProjectDirectories(projectId);
const directories = await sourceFilesApi.withFetchAll().listProjectDirectories(projectId, branchId);
let directory = directories.data.find(d => d.data.name === getDirectoryName(page));
if (!directory) {
ui.message(displayTexts.notifications.info.creatingNewDirectory);
directory = await sourceFilesApi.createDirectory(projectId, {
name: getDirectoryName(page),
title: page.name
title: page.name,
branchId
});
}

Expand Down
137 changes: 137 additions & 0 deletions src/action/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import ui from 'sketch/ui';
import dom from 'sketch/dom';
import settings from 'sketch/settings';
import {
ACCESS_TOKEN_KEY,
PROJECT_ID,
ORGANIZATION,
OVERRIDE_TRANSLATIONS,
CONTENT_SEGMENTATION,
DEFAULT_STRINGS_KEY_NAMING_OPTION,
KEY_NAMING_PATTERN,
STRINGS_KEY_NAMING_OPTIONS,
BRANCH_ID
} from '../constants';
import { default as displayTexts } from '../../assets/texts.json';

function contactUs() {
NSWorkspace.sharedWorkspace().openURL(NSURL.URLWithString("https://crowdin.com/contacts"));
}

function getCredentials() {
let token = settings.settingForKey(ACCESS_TOKEN_KEY);
if (!!token && token.length > 3) {
token = token.substring(0, 3) + '...';
}
const organization = settings.settingForKey(ORGANIZATION);
return { token, organization };
}

function getOverrideTranslations() {
if (!dom.getSelectedDocument()) {
ui.message(displayTexts.notifications.warning.selectDocument);
return { overrideTranslations: false };
}
return {
overrideTranslations: settings.documentSettingForKey(dom.getSelectedDocument(), OVERRIDE_TRANSLATIONS)
};
}

function saveOverrideTranslations(value) {
if (!dom.getSelectedDocument()) {
ui.message(displayTexts.notifications.warning.selectDocument);
return;
}
settings.setDocumentSettingForKey(dom.getSelectedDocument(), OVERRIDE_TRANSLATIONS, value);
ui.message(displayTexts.notifications.info.overrideTranslationsSaved);
}

function getContentSegmentation() {
if (!dom.getSelectedDocument()) {
ui.message(displayTexts.notifications.warning.selectDocument);
return { contentSegmentation: true };
}
const value = settings.documentSettingForKey(dom.getSelectedDocument(), CONTENT_SEGMENTATION);
return {
contentSegmentation: value === undefined ? true : !!value
};
}

function saveContentSegmentation(value) {
if (!dom.getSelectedDocument()) {
ui.message(displayTexts.notifications.warning.selectDocument);
return;
}
settings.setDocumentSettingForKey(dom.getSelectedDocument(), CONTENT_SEGMENTATION, !!value);
ui.message(displayTexts.notifications.info.contentSegmentationSaved);
}

function getKeyPatternOptions() {
let selectedOption = !!dom.getSelectedDocument() && !!settings.documentSettingForKey(dom.getSelectedDocument(), KEY_NAMING_PATTERN)
? parseInt(settings.documentSettingForKey(dom.getSelectedDocument(), KEY_NAMING_PATTERN))
: DEFAULT_STRINGS_KEY_NAMING_OPTION;
return STRINGS_KEY_NAMING_OPTIONS.map(e => {
return {
selected: selectedOption === e.id,
...e
};
})
}

function saveKeyPatternOption(value) {
if (!dom.getSelectedDocument()) {
ui.message(displayTexts.notifications.warning.selectDocument);
return;
}
settings.setDocumentSettingForKey(dom.getSelectedDocument(), KEY_NAMING_PATTERN, value);
ui.message(displayTexts.notifications.info.stringsKeyNamingSaved);
}

function saveCredentials(creds) {
const token = settings.settingForKey(ACCESS_TOKEN_KEY);
let initValue = undefined;
if (!!token && token.length > 3) {
initValue = token.substring(0, 3) + '...';
}
if (creds.token !== initValue) {
settings.setSettingForKey(ACCESS_TOKEN_KEY, creds.token);
}
settings.setSettingForKey(ORGANIZATION, creds.organization);
ui.message(displayTexts.notifications.info.credentialsSaved);
}

function saveProject(projectId) {
if (!dom.getSelectedDocument()) {
ui.message(displayTexts.notifications.warning.selectDocument);
return;
}
settings.setDocumentSettingForKey(dom.getSelectedDocument(), PROJECT_ID, projectId);
if (!!projectId) {
ui.message(displayTexts.notifications.info.projectSaved);
}
}

function saveBranch(branchId) {
if (!dom.getSelectedDocument()) {
ui.message(displayTexts.notifications.warning.selectDocument);
return;
}
settings.setDocumentSettingForKey(dom.getSelectedDocument(), BRANCH_ID, branchId);
if (!!branchId) {
ui.message(displayTexts.notifications.info.branchSaved);
}
}

export {
contactUs,
getCredentials,
getOverrideTranslations,
saveOverrideTranslations,
getContentSegmentation,
saveContentSegmentation,
getKeyPatternOptions,
saveKeyPatternOption,
saveCredentials,
saveProject,
saveBranch
};
2 changes: 0 additions & 2 deletions src/action/strings-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,4 @@ function extractPageTranslations(languageName, document, page, translations) {

}



export { stringsPreview };
6 changes: 4 additions & 2 deletions src/action/translate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ui from 'sketch/ui';
import dom from 'sketch/dom';
import settings from 'sketch/settings';
import { PROJECT_ID, ACCESS_TOKEN_KEY, TEXT_TYPE, SYMBOL_TYPE } from '../constants';
import { PROJECT_ID, ACCESS_TOKEN_KEY, TEXT_TYPE, SYMBOL_TYPE, BRANCH_ID } from '../constants';
import * as domUtil from '../util/dom';
import * as httpUtil from '../util/http';
import * as localStorage from '../util/local-storage';
Expand All @@ -21,6 +21,8 @@ async function translate(languageId, wholePage) {
}
const selectedPage = selectedDocument ? selectedDocument.selectedPage : undefined;
const projectId = settings.documentSettingForKey(selectedDocument, PROJECT_ID);
let branchId = settings.documentSettingForKey(dom.getSelectedDocument(), BRANCH_ID);
branchId = !!branchId && branchId > 0 ? branchId : undefined;
let artboard;

if (!selectedPage) {
Expand Down Expand Up @@ -68,7 +70,7 @@ async function translate(languageId, wholePage) {

if (selectedLanguages.length > 0) {
try {
const directories = await sourceFilesApi.withFetchAll().listProjectDirectories(projectId);
const directories = await sourceFilesApi.withFetchAll().listProjectDirectories(projectId, branchId);
const directory = directories.data.find(d => d.data.name === getDirectoryName(selectedPage));
if (!directory) {
if (wholePage) {
Expand Down
4 changes: 2 additions & 2 deletions src/action/upload-screenshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ async function uploadScreenshots() {
artboards = artboards.filter(artboard => !translatedArtboards.includes(artboard.id));

//removing obsolete tags
const { sourceStringsApi, screenshotsApi } = httpUtil.createClient();
const strings = await fetchStrings(projectId, sourceStringsApi);
const { screenshotsApi } = httpUtil.createClient();
const strings = await fetchStrings(projectId);
const stringsIds = strings.map(st => st.id)

const screenshotsBefore = [];
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const KEY_PREFIX = 'crowdin';
export const ACCESS_TOKEN_KEY = `${KEY_PREFIX}-access-token`;
export const ORGANIZATION = `${KEY_PREFIX}-organization`;
export const PROJECT_ID = `${KEY_PREFIX}-project-id`;
export const BRANCH_ID = `${KEY_PREFIX}-branch-id`;
export const OVERRIDE_TRANSLATIONS = `${KEY_PREFIX}-override-translations`;
export const CONTENT_SEGMENTATION = `${KEY_PREFIX}-content-segmentation`;
export const KEY_NAMING_PATTERN = `${KEY_PREFIX}-key-naming`;
Expand Down
Loading