Skip to content

Commit

Permalink
Creating field for language in prefs form
Browse files Browse the repository at this point in the history
  • Loading branch information
Cris Silva Jr committed Apr 15, 2018
1 parent 30319de commit 75afc62
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Assets/translation.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ID Language File Edit Help Quit Preferences Help Start Next Name Results Contact Finish Save Cancel Docs All Instruct Data
EN English File Edit Hep Quit Preferences Help Start Next Name Results saved Contact the test's applicator Finish Save Cancel Documentation Answer all questions Click the button below to proceed Data
PT-BR Português Brasileiro Arquivo Editar Ajuda Sair Preferências Ajuda Sair Continuar Nome Resultados salvos com sucesso! Contate o aplicador do teste. Finalizar Salvar Cancelar Documentação Responda todas as perguntas. Aperte o botão abaixo para continuar. Dados
ID Language File Edit Help Quit Preferences Help Start Next Name Results Contact Finish Save Cancel Docs All Instruct Data TextAbout About Language
EN English File Edit Hep Quit Preferences Help Start Next Name Results saved Contact the test's applicator Finish Save Cancel Documentation Answer all questions Click the button below to proceed Data ScalemateForms was written by Cris Silva Jr. (http://www.crisjr.eng.br) in the Laboratory of Neuroscience and Behaviour from the University of Brasília. It was released under the MIT License (https://opensource.org/licenses/MIT) About Language
PT-BR Português Brasileiro Arquivo Editar Ajuda Sair Preferências Ajuda Sair Continuar Nome Resultados salvos com sucesso! Contate o aplicador do teste. Finalizar Salvar Cancelar Documentação Responda todas as perguntas. Aperte o botão abaixo para continuar. Dados ScalemateForms foi escrito por Cris Silva Jr. (http://www.crisjr.eng.br) no Laboratório de Neurociência e Comportamento da Universidade de Brasília e foi lançado sob a licença MIT (https://opensource.org/licenses/MIT). Sobre Idioma
21 changes: 20 additions & 1 deletion Scalemate/ScalemateForms/View/FormInventory.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Scalemate/ScalemateForms/View/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Scalemate;
using ScalemateForms.Model;
using ScalemateForms.View.Util;
using System.Linq;

namespace ScalemateForms.View
{
Expand Down Expand Up @@ -92,9 +93,28 @@ private void docsStripMenuItem_Click(object sender, EventArgs e)
form.Show();
}

#region IParent implementation
public string Get(string tag)
{
return Translator.Get(tag);
}

public string Set(string code)
{
Translator.SetPreferredLanguage(code);
return code;
}

public string[] GetLanguages()
{
// XXX Maybe this should be on the translator? The designer can't know about this, right?
return GetCodes().Select(code => Translator.Translations[code]["LONG_ID"]).ToArray();
}

public string[] GetCodes()
{
return Translator.Translations.Keys.ToArray();
}
#endregion
}
}
31 changes: 30 additions & 1 deletion Scalemate/ScalemateForms/View/FormPreferences.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 26 additions & 3 deletions Scalemate/ScalemateForms/View/FormPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ namespace ScalemateForms.View
{
public partial class FormPreferences : Form
{
private Form Mother { get; set; }
private IParent Mother { get; set; }

public FormPreferences(Form mother)
public FormPreferences(IParent mother)
{
// Preparing form
InitializeComponent();
WindowState = FormWindowState.Maximized;
Mother = mother;
textAbout.Text = "ScalemateForms foi escrito por Cris Silva Jr. (http://www.crisjr.eng.br) no Laboratório de Neurociência e Comportamento da Universidade de Brasília, e foi lançado sob a licença MIT (https://opensource.org/licenses/MIT).";
ManageLanguages();
Translate();

// Setting languages for translation

}

private void buttonSave_Click(object sender, EventArgs e)
Expand All @@ -32,5 +37,23 @@ private void buttonCancel_Click(object sender, EventArgs e)
{
this.Close();
}

private void ManageLanguages()
{
string[] languages = Mother.GetLanguages();
foreach (string language in languages)
{
comboBoxLanguage.Items.Add(language);
}
comboBoxLanguage.SelectedIndex = 0;
}

private void Translate()
{
labelAbout.Text = Mother.Get("About");
textAbout.Text = Mother.Get("TextAbout");
labelLanguage.Text = Mother.Get("Language");
buttonCancel.Text = Mother.Get("Cancel");
}
}
}
3 changes: 3 additions & 0 deletions Scalemate/ScalemateForms/View/IParent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ public interface IParent
void Show();
void Hide();
string Get(string tag);
string Set(string tag);
string[] GetLanguages();
string[] GetCodes();
}
}
2 changes: 1 addition & 1 deletion Scalemate/ScalemateForms/View/Util/TranslationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void SetPreferredLanguage(string code)
}

public string Code { get; private set; }
public Dictionary<string, Dictionary<string, string>> Translations;
public Dictionary<string, Dictionary<string, string>> Translations { get; private set; }
private DataAccessLayer DAL;
}
}

0 comments on commit 75afc62

Please sign in to comment.