Example #1
0
        // Works. https://new-translate-web-staging.unity3d.jp/api/file-api/upload-source-file
        // TODO: Need a way to extract source file in PO format without translations.
        // TODO: References (Starts With "#:") in LANG file need be 'per-key' and not 'per-language'
        // FIXIT: In case of original file being NOT in PO file format, if we need to update it, it'll be wasted, as we're sending only PO files out.
        private static void UploadSourceFile(string localFilePath, TranslateProject projectSettings)
        {
            var fileEntry      = new Dictionary <string, object>();
            var remoteFilePath = GetServerPathForLocalPath(localFilePath);

            fileEntry["name"]     = remoteFilePath;
            fileEntry["mimeType"] = "application/x-po";

            var fileContent = GetFileDataInPoFormat(localFilePath,
                                                    SystemLanguage.Arabic, projectSettings); // TODO: FixIt ^^^

            fileEntry["text"] = fileContent;

            var filesToUpload = new List <object>();

            filesToUpload.Add(fileEntry);

            var data = new Dictionary <string, object>();

            data["uploadFiles"] = filesToUpload;

            var jsonData = Json.Serialize(data);

            Downloader.Response response;
            Downloader.SendGetPostData(serverUrl
                                       + "/v1/projects/" + projectSettings.id
                                       + "/" + projectSettings.currentBranch
                                       + "/files"
                                       , jsonData
                                       , out response);
        }
Example #2
0
        // Works. https://new-translate-web-staging.unity3d.jp/api/project-api/get-file-list
        public static List <string> GetListOfFiles(TranslateProject projectSettings)
        {
            Downloader.Response response;
            Downloader.SendGetData(serverUrl
                                   + "/v1/projects/" + projectSettings.id
                                   + "/" + projectSettings.currentBranch
                                   + "/files?type=simple"
                                   , out response);

            var listOfFiles = Json.Deserialize(response.body) as Dictionary <string, object>;

            return(((List <object>)listOfFiles["files"]).ConvertAll(x => x.ToString()));
        }
Example #3
0
        public static TranslateProject GetProjectDataForEditor()
        {
            var project = new TranslateProject();

            return(project);
        }
Example #4
0
        // Works.
        // Gets TranslationFile. Converts it to 'Language' file format. Saves it in Assets project
        // folder in the same relative path as was on the server.
        private static void SaveTranslationFileToProjectLanguageFile(TranslationFile translationFile, TranslateProject projectSettings)
        {
            var tempPath = Path.GetTempFileName();

            File.WriteAllText(tempPath, translationFile.content);

            var db = GetMultiLangStringDB(translationFile.pathOnServer);

            POUtility.ImportFile(db, tempPath, (SystemLanguage)projectSettings.sourceLanguageID, true); // TODO: 1. Update reference language from settings. 2. Q.: When last param true and when false?
            File.Delete(tempPath);

            SaveLangDBFileAtPath(db, translationFile.pathOnServer);
        }
Example #5
0
        // Works. Takes file name as it is on server. Downloads it. Returns as TranslationFile.
        private static TranslationFile DownloadTranslationFile(string filePathOnServer, SystemLanguage translationLanguage, TranslateProject projectSettings)
        {
            var translationFile = new TranslationFile();

            translationFile.pathOnServer = filePathOnServer;
            filePathOnServer             = WWW.EscapeURL(filePathOnServer);

            Downloader.Response response;
            Downloader.SendGetData(serverUrl
                                   + "/v1/files/translation-file?projectID=" + projectSettings.id
                                   + "&languageID=" + serverLanguageCodes[translationLanguage.ToString()]
                                   + "&branch=" + projectSettings.currentBranch
                                   + "&file=" + filePathOnServer,
                                   out response);
            translationFile.content = response.body;

            return(translationFile);
        }
Example #6
0
        // Works. Same as GetTranslationFile() but for all files in the list.
        // There's an option here (https://new-translate-web-staging.unity3d.jp/api/file-api/get-translated-file)
        // to download all files in one batch, but it was failing at the moment of implementation.
        public static void DownloadAndSaveAllTranslationFiles(SystemLanguage translationLanguage, TranslateProject projectSettings)
        {
            var listOfAllTransaltionFilesOnServer = GetListOfFiles(projectSettings);

            foreach (var translationFilePath in listOfAllTransaltionFilesOnServer)
            {
                var translationFile = DownloadTranslationFile(translationFilePath,
                                                              translationLanguage, projectSettings);
                SaveTranslationFileToProjectLanguageFile(translationFile, projectSettings);
            }
        }
Example #7
0
        // Appears to work OK
        private static string GetFileDataInPoFormat(string localFilePath, SystemLanguage targetLanguage, TranslateProject projectSettings)
        {
            var db       = GetMultiLangStringDB(localFilePath);
            var tempPath = Path.GetTempFileName();

            POUtility.ExportFile(db, targetLanguage,
                                 (SystemLanguage)projectSettings.sourceLanguageID, tempPath);

            var convertedContent = File.ReadAllText(tempPath);

            File.Delete(tempPath);
            return(convertedContent);
        }
Example #8
0
        // https://new-translate-web-staging.unity3d.jp/api/file-api/upload-translation-file
        private static void SendTranslationFileToServer(string localFilePath, SystemLanguage targetLanguage, TranslateProject projectSettings)
        {
            var uploadFile          = new Dictionary <string, object>();
            var translationFilePath = Path.ChangeExtension(localFilePath, ".po");

            uploadFile["name"]     = translationFilePath;
            uploadFile["mimeType"] = "application/x-po";
            var fileContent = GetFileDataInPoFormat(localFilePath, targetLanguage, projectSettings);

            uploadFile["text"] = fileContent;

            var data = new Dictionary <string, object>();

            data["projectID"]  = projectSettings.id;
            data["branch"]     = projectSettings.currentBranch;
            data["languageID"] = serverLanguageCodes[targetLanguage.ToString()];
            var sourceFilePath = GetServerPathForLocalPath(localFilePath);

            data["filename"]   = sourceFilePath;
            data["uploadFile"] = uploadFile;

            var jsonData = Json.Serialize(data);

            Downloader.Response response;
            Downloader.SendGetPostData(serverUrl + "/v1/files/translation-file"
                                       , jsonData, out response);
        }
Example #9
0
        //Should check if the file is there or if it is of the same version/condition.
        // https://new-translate-api-staging.unity3d.jp/v1/files/source-file/actions/verify?projectID=1&branch=topics&file=Best%20Practices%2F1-1.physics_best_practices.md&md5=dd9391cd42e5bf63888208e2b835172c
        private static bool IsSourceFileOnServerAndIsNotModified(string localFilePath, TranslateProject projectSettings)
        {
            string serverFilePath   = GetServerPathForLocalPath(localFilePath);
            var    absoluteFilePath = GetAbsoluteFilePath(localFilePath);
            // TODO: Fix it. Hash for proper source file (updated or not) and not for the LANG DB file.
            var md5        = GetMD5HashForFileContent(absoluteFilePath);
            var requestURL = serverUrl + "/v1/files/source-file/actions/verify?"
                             + "projectID=" + projectSettings.id
                             + "&branch=" + projectSettings.currentBranch
                             + "&file=" + serverFilePath
                             + "&md5=" + md5;

            Downloader.Response response;
            var success = Downloader.SendGetData(requestURL, out response);

            // if (success && response.body.Contains("true"))
            if (success) // Use the above ^ IF condition after proper MD5 check is in place
            {
                return(true);
            }
            return(false);
        }
Example #10
0
 public static void UploadTranslationFile(string localFilePath, SystemLanguage translationLanguage, TranslateProject projectSettings)
 {
     if (!IsSourceFileOnServerAndIsNotModified(localFilePath, projectSettings))
     {
         // FIXIT: We need to keep track of MSGID changes;
         // keep local copy of Source file and update if MSGIDs changed/added/removed;
         // And only then we may upload it to server;
         // ...in case it is not in PO format, but e.g. simple text file.
         UploadSourceFile(localFilePath, projectSettings);
     }
     SendTranslationFileToServer(localFilePath, translationLanguage, projectSettings);
 }
Example #11
0
        // Works. For single file: https://new-translate-web-staging.unity3d.jp/api/file-api/get-translation-file
        // Downloading the file and converting it to Language-file format.
        public static void GetTranslationFile(string filePathOnServer, SystemLanguage translationLanguage, TranslateProject projectSettings)
        {
            // TODO: filePathOnServer - we need to save it for every LANG DB file we're using.
            var translationFile = DownloadTranslationFile(filePathOnServer, translationLanguage, projectSettings);

            SaveTranslationFileToProjectLanguageFile(translationFile, projectSettings);
        }