Skip to content

Commit 0367402

Browse files
author
Chris Gårdenberg
committed
Adding new languages.json dependency
Removing `Debugger.Break();` from the buildtask Removing Examplefiles-folder (not needed) Updating README
1 parent 0da5c90 commit 0367402

9 files changed

Lines changed: 71 additions & 40 deletions

File tree

MN.L10n/ExampleFiles/language-en-GB.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

MN.L10n/ExampleFiles/language-sv-SE.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

MN.L10n/ExampleFiles/phrases.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

MN.L10n/FileProviders/FileDataProvider.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,41 @@ public class FileDataProvider : IL10nDataProvider
1010

1111
private string FilePath { get; set; }
1212
private string PhraseFile { get; set; }
13+
private string LanguagesFile { get; set; }
1314
private string LanguageFile { get; set; }
14-
public FileDataProvider(string path, string l10nFileName = "phrases.json", string l10nPhraseFileNameFormat = "language-{0}.json")
15+
public FileDataProvider(string path, string l10nFileName = "phrases.json", string l10nPhraseFileNameFormat = "language-{0}.json", string l10nLanguagesFileName = "languages.json")
1516
{
1617
FilePath = path;
1718
PhraseFile = l10nFileName;
19+
LanguagesFile = l10nLanguagesFileName;
1820
LanguageFile = l10nPhraseFileNameFormat;
1921
}
2022
public L10n LoadL10n()
2123
{
2224
var tp = new NGettext.Plural.Ast.AstTokenParser();
2325

26+
var langPath = Path.Combine(FilePath, LanguagesFile);
27+
List<string> languages = new List<string> { "default" };
28+
29+
if (File.Exists(langPath))
30+
{
31+
var contents = File.ReadAllText(langPath);
32+
languages = JSON.Deserialize<List<string>>(contents);
33+
}
34+
2435
var phrasePath = Path.Combine(FilePath, PhraseFile);
2536
L10n l10n;
2637
if (File.Exists(phrasePath))
2738
{
2839
var l10nFileContents = File.ReadAllText(phrasePath);
2940
l10n = JSON.Deserialize<L10n>(l10nFileContents, SerializerOptions);
41+
l10n.Languages = languages;
3042
}
3143
else
3244
{
3345
l10n = new L10n
3446
{
35-
Languages = new List<string> { "default" }
47+
Languages = languages
3648
};
3749
File.WriteAllText(phrasePath, JSON.Serialize(l10n, SerializerOptions));
3850
}

MN.L10n/L10n.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public static L10n CreateInstance(IL10nLanguageProvider langProvider, IL10nDataP
2222
Instance = l10n;
2323
return l10n;
2424
}
25+
26+
[JilDirective(Ignore = true)]
2527
public List<string> Languages { get; set; } = new List<string>();
2628
public Dictionary<string, L10nPhrase> Phrases { get; set; } = new Dictionary<string, L10nPhrase>();
2729

MN.L10n/L10nBuildTask.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public override bool Execute()
2020
var sourceDir = Environment.CurrentDirectory;
2121
Log.LogMessage(MessageImportance.High, "info l10n: L10n - beginning work: " + sourceDir);
2222

23-
Debugger.Break();
2423
Stopwatch stw = new Stopwatch();
2524
stw.Start();
2625

MN.L10n/MN.L10n.csproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@ Translation package</Description>
1212
<PackageProjectUrl>https://github.com/MultinetInteractive/MN.L10n</PackageProjectUrl>
1313
<RepositoryType>git</RepositoryType>
1414
<Copyright>© 20XX MultiNet Interactive AB</Copyright>
15-
<Version>1.0.101</Version>
15+
<Version>1.0.107</Version>
1616
<AutoIncrementPackageRevision>True</AutoIncrementPackageRevision>
17+
<PackageReleaseNotes>## 1.0.107
18+
- I kinda missed a semicolon in the targets-file..
19+
20+
## 1.0.106
21+
- Updated README
22+
23+
## 1.0.105
24+
- Added separate file to store Languages in
25+
- Files to store in Solution = languages.json and all language-{0}.json-files</PackageReleaseNotes>
1726
</PropertyGroup>
1827

1928
<ItemGroup>

MN.L10n/build/MN.L10n.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
</BuildDependsOn>
1010
</PropertyGroup>
1111

12-
<Target Name="L10n" AfterTargets="AfterBuild">
12+
<Target Name="L10n" AfterTargets="BeforeBuild">
1313
<L10nBuildTask/>
1414
<ItemGroup>
15-
<L10nLanguageFiles Include="$(SolutionDir)phrases.json;$(SolutionDir)language-*.json" />
15+
<L10nLanguageFiles Include="$(SolutionDir)phrases.json;$(SolutionDir)languages.json;$(SolutionDir)language-*.json" />
1616
</ItemGroup>
1717
<Message Importance="high" Text="Copying phrase-files from @(L10nLanguageFiles) to $(ProjectDir)L10n\" />
1818
<Copy SourceFiles="@(L10nLanguageFiles)" DestinationFolder="$(ProjectDir)L10n\" />

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# MN.L10n [![Build status](https://ci.appveyor.com/api/projects/status/y5uh8gvxm29v90rk?svg=true)](https://ci.appveyor.com/project/itssimple/mn-l10n)
1+
# MN.L10n [![Build status](https://ci.appveyor.com/api/projects/status/y5uh8gvxm29v90rk?svg=true)](https://ci.appveyor.com/project/itssimple/mn-l10n)
22
Translation-thingy for all our products
33

44
You must implement your `IL10nLanguageProvider` and a custom `IFileResolver` (for javascript) yourself. :) (Basically just `string GetLanguage()` and `bool FileExists(string file)`)
@@ -57,7 +57,7 @@ Response.Write("<script type=\"text/javascript\">" +
5757

5858
```javascript
5959
DealDetails.ShowNotification(
60-
_s('Sparade en ny notering på $companyName$',
60+
_s('Sparade en ny notering på $companyName$',
6161
{ companyName: DealDetails.DealInfo.CompanyName }
6262
)
6363
);
@@ -91,6 +91,47 @@ protected void Application_Start(object sender, EventArgs e)
9191

9292
---
9393

94+
# Example files
95+
96+
## languages.json
97+
98+
```json
99+
[ "sv_SE", "en_GB" ]
100+
```
101+
102+
## phrases.json
103+
104+
```json
105+
{
106+
Phrases: {
107+
"Hello world": {
108+
"Created": "2017-01-01T00:00:00.000Z",
109+
"Usages": 1,
110+
"Comment": "Standard phrase, found everywhere."
111+
}
112+
}
113+
}
114+
```
115+
116+
## language-sv_SE.json
117+
118+
```json
119+
{
120+
"LanguageName": "Svenska",
121+
"Locale": "sv-SE",
122+
"PluralizationRules": [ "0", "1" ],
123+
"PluralRule": "(n != 1)",
124+
"Phrases": {
125+
"Hello world": {
126+
"r": {
127+
"0": "Hej världen"
128+
}
129+
}
130+
}
131+
}
132+
```
133+
---
134+
94135
#### Things we use in the code to make the magic happen
95136
- [Glob.cs](https://github.com/mganss/Glob.cs)
96137
- [CommonMark.NET](https://github.com/Knagis/CommonMark.NET)

0 commit comments

Comments
 (0)