コード例 #1
0
        private async void LoadLanguagesList()
        {
            this.ProjectInfo = await TransifexConnector.ProjectDetails();

            this.ProjectInfo.Teams.ForEach(t => { if (!this.DownloadingResources.ContainsKey(t))
                                                  {
                                                      this.DownloadingResources.Add(t, false);
                                                  }
                                           });

            this.CreateLangueCacheFolderIfNOtExist(this.ProjectInfo.Teams);
            this.comboBoxLanguages.DataSource    = new BindingSource(this.ProjectInfo.Languages, null);
            this.comboBoxLanguages.DisplayMember = "Name";
            this.comboBoxLanguages.ValueMember   = "Code";
            this.comboBoxLanguages.Text          = string.Empty;
            this.comboBoxLanguages.Enabled       = true;

            // Previous selected language
            var previousLanguageCode = Properties.Settings.Default.SelectedLanguage;
            var previousSelection    = comboBoxLanguages.Items.Cast <Language>().ToList().FirstOrDefault(i => i.Code == previousLanguageCode);

            if (previousSelection != null)
            {
                comboBoxLanguages.SelectedItem = previousSelection;
            }
        }
コード例 #2
0
        private async void comboBoxLanguages_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.buttonApply.Visible = false;

            if (comboBoxLanguages.SelectedItem is Language)
            {
                this.labelProgression.Text = "Loading transifex translations files...";
                var langCode            = ((Language)comboBoxLanguages.SelectedItem).Code;
                int previousProgression = TransifexConnector.GetLastProgressionFromDataFile(langCode);
                this.CurrentTranslationInfo = await TransifexConnector.TranslationDetails(langCode);

                // Download and Cache files if not currently downloading
                if (!this.DownloadingResources[langCode])
                {
                    // Check if new translations occured (if force download, download will happen when user click apply...)
                    if (previousProgression != this.CurrentTranslationInfo.Translated_segments && !this.checkBoxForceDl.Checked)
                    {
                        await this.DownloadTranslationFile(langCode, this.CurrentTranslationInfo.Total_segments);
                    }
                }

                this.buttonApply.Visible = true;
                this.progressBarDownlodResources.Visible = false;

                this.labelProgression.Text   = this.CurrentTranslationInfo.PercentProgression.ToString() + " %";
                this.labelResourcesInfo.Text = ProjectInfo.Resources.Count + " files and " + this.CurrentTranslationInfo.Translated_segments.ToString() + "/" + this.CurrentTranslationInfo.Total_segments.ToString() + " translated sentences";
            }
        }
コード例 #3
0
        private async Task DownloadTranslationFile(string langCode, int totalSegments)
        {
            this.DownloadingResources[langCode] = true;

            // Calculate file size for progress
            this.progressBarDownlodResources.Visible = true;
            this.progressBarDownlodResources.Value   = 0;
            this.progressBarDownlodResources.Maximum = TransifexConnector.GetTotalResouresSize(langCode, this.ProjectInfo.Resources, totalSegments);
            this.progressBarDownlodResources.Step    = 1024;

            // Progress reporter
            var progress = new Progress <int>();

            progress.ProgressChanged += (s, percent) =>
            {
                progressBarDownlodResources.PerformStep();
            };

            // Download file
            if (this.checkBoxLiveUpdate.Checked)
            {
                // from transifex website
                try
                {
                    await TransifexConnector.DownloadTranslationResources(langCode, this.ProjectInfo.Resources, progress);
                }
                catch
                {
                    var dialogResult = MessageBox.Show(
                        "Transifex website reject download request.\r\nLast available translation can't be download\r\nDo you want to download backup ?",
                        "Revert changes success",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Error);
                    if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                    {
                    }
                }
            }
            else
            {
                // backuo available in dropbox
                await DropboxConnector.DownloadTranslationResources(langCode, this.ProjectInfo.Resources, progress);
            }

            this.DownloadingResources[langCode] = false;
        }