Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRoger committed Jun 9, 2021
0 parents commit 6d4f829
Show file tree
Hide file tree
Showing 18 changed files with 755 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/

# Visual Studio Code
.vscode

# Rider
.idea

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
msbuild.log
msbuild.err
msbuild.wrn

# Visual Studio 2015
.vs/
ProjectBook/Properties/PublishProfiles/FolderProfile.pubxml
ProjectBook/ApiKeys.cs
103 changes: 103 additions & 0 deletions GlobalStrings.Sample/Form1.Designer.cs

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

39 changes: 39 additions & 0 deletions GlobalStrings.Sample/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using GlobalStrings;
using System.Windows.Forms;
using GlobalStrings.Sample.Strings;
using System.Drawing;

namespace GlobalStrings.Sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

LanguageManager.GetGlobalizationInstance().LangTextObserver += Form1_LangTextObserver;
LanguageManager.GetGlobalizationInstance().StartGlobalization();
Load += (_, _) => cmbLanguages.SelectedIndex = 0;
}

private void Form1_LangTextObserver(object sender, UpdateModeEventArgs updateModeEventArgs)
{
btnSizeDemo.Size = updateModeEventArgs.lang switch
{
"pt_br" => new Size(200, 23),
"en" => new Size(190, 23)
};
lblTextPlaceholder.Text = LanguageManager.GetGlobalizationInstance().SetText(0);
btnChangeLang.Text = LanguageManager.GetGlobalizationInstance().SetText(1);
btnSizeDemo.Text = LanguageManager.GetGlobalizationInstance().SetText(2);
}

private void btnChangeLang_Click(object sender, EventArgs e)
{
string keyLang = cmbLanguages.SelectedItem.ToString() == "Português (Brasil)" ? "pt_br" : "en";

LanguageManager.GetGlobalizationInstance().UpdateLang(keyLang);
}
}
}
60 changes: 60 additions & 0 deletions GlobalStrings.Sample/Form1.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
13 changes: 13 additions & 0 deletions GlobalStrings.Sample/GlobalStrings.Sample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\GlobalStrings\GlobalStrings.csproj" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions GlobalStrings.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GlobalStrings.Sample
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
14 changes: 14 additions & 0 deletions GlobalStrings.Sample/Strings/LanguageManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace GlobalStrings.Sample.Strings
{
public static class LanguageManager
{
private static Globalization<string, int> globalization;
private static Languages langs = new();

public static Globalization<string, int> GetGlobalizationInstance()
{
if(globalization == null) globalization = new(langs.languageList, "pt_br");
return globalization;
}
}
}
36 changes: 36 additions & 0 deletions GlobalStrings.Sample/Strings/Languages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GlobalStrings;

namespace GlobalStrings.Sample.Strings
{
public class Languages
{
public LanguageInfo<string, int> ptBr { get; set; }
public LanguageInfo<string, int> en {get; set;}
public List<LanguageInfo<string, int>> languageList { get {
return new List<LanguageInfo<string, int>> {ptBr, en};
}
}

public Languages()
{
ptBr = new("pt_br");
Dictionary<int, string> ptBrDictionary = new();
ptBrDictionary.Add(0, "Olá");
ptBrDictionary.Add(1, "Mudar idioma");
ptBrDictionary.Add(2, "Esse botão muda seu tamanho");
ptBr.textLangBook = ptBrDictionary;

en = new("en");
Dictionary<int, string> enDictionary = new();
enDictionary.Add(0, "Hello");
enDictionary.Add(1, "Change language");
enDictionary.Add(2, "This button changes its size");
en.textLangBook = enDictionary;
}
}
}
26 changes: 26 additions & 0 deletions GlobalStrings.Test/GlobalStrings.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GlobalStrings\GlobalStrings.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit 6d4f829

Please sign in to comment.