Skip to content

Commit

Permalink
Adding new languages.json dependency
Browse files Browse the repository at this point in the history
Removing `Debugger.Break();` from the buildtask
Removing Examplefiles-folder (not needed)
Updating README
  • Loading branch information
itssimple committed Oct 3, 2017
1 parent 0da5c90 commit 0367402
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 40 deletions.
12 changes: 0 additions & 12 deletions MN.L10n/ExampleFiles/language-en-GB.json

This file was deleted.

12 changes: 0 additions & 12 deletions MN.L10n/ExampleFiles/language-sv-SE.json

This file was deleted.

8 changes: 0 additions & 8 deletions MN.L10n/ExampleFiles/phrases.json

This file was deleted.

16 changes: 14 additions & 2 deletions MN.L10n/FileProviders/FileDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,41 @@ public class FileDataProvider : IL10nDataProvider

private string FilePath { get; set; }
private string PhraseFile { get; set; }
private string LanguagesFile { get; set; }
private string LanguageFile { get; set; }
public FileDataProvider(string path, string l10nFileName = "phrases.json", string l10nPhraseFileNameFormat = "language-{0}.json")
public FileDataProvider(string path, string l10nFileName = "phrases.json", string l10nPhraseFileNameFormat = "language-{0}.json", string l10nLanguagesFileName = "languages.json")
{
FilePath = path;
PhraseFile = l10nFileName;
LanguagesFile = l10nLanguagesFileName;
LanguageFile = l10nPhraseFileNameFormat;
}
public L10n LoadL10n()
{
var tp = new NGettext.Plural.Ast.AstTokenParser();

var langPath = Path.Combine(FilePath, LanguagesFile);
List<string> languages = new List<string> { "default" };

if (File.Exists(langPath))
{
var contents = File.ReadAllText(langPath);
languages = JSON.Deserialize<List<string>>(contents);
}

var phrasePath = Path.Combine(FilePath, PhraseFile);
L10n l10n;
if (File.Exists(phrasePath))
{
var l10nFileContents = File.ReadAllText(phrasePath);
l10n = JSON.Deserialize<L10n>(l10nFileContents, SerializerOptions);
l10n.Languages = languages;
}
else
{
l10n = new L10n
{
Languages = new List<string> { "default" }
Languages = languages
};
File.WriteAllText(phrasePath, JSON.Serialize(l10n, SerializerOptions));
}
Expand Down
2 changes: 2 additions & 0 deletions MN.L10n/L10n.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static L10n CreateInstance(IL10nLanguageProvider langProvider, IL10nDataP
Instance = l10n;
return l10n;
}

[JilDirective(Ignore = true)]
public List<string> Languages { get; set; } = new List<string>();
public Dictionary<string, L10nPhrase> Phrases { get; set; } = new Dictionary<string, L10nPhrase>();

Expand Down
1 change: 0 additions & 1 deletion MN.L10n/L10nBuildTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public override bool Execute()
var sourceDir = Environment.CurrentDirectory;
Log.LogMessage(MessageImportance.High, "info l10n: L10n - beginning work: " + sourceDir);

Debugger.Break();
Stopwatch stw = new Stopwatch();
stw.Start();

Expand Down
11 changes: 10 additions & 1 deletion MN.L10n/MN.L10n.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@ Translation package</Description>
<PackageProjectUrl>https://github.com/MultinetInteractive/MN.L10n</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<Copyright>© 20XX MultiNet Interactive AB</Copyright>
<Version>1.0.101</Version>
<Version>1.0.107</Version>
<AutoIncrementPackageRevision>True</AutoIncrementPackageRevision>
<PackageReleaseNotes>## 1.0.107
- I kinda missed a semicolon in the targets-file..

## 1.0.106
- Updated README

## 1.0.105
- Added separate file to store Languages in
- Files to store in Solution = languages.json and all language-{0}.json-files</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions MN.L10n/build/MN.L10n.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
</BuildDependsOn>
</PropertyGroup>

<Target Name="L10n" AfterTargets="AfterBuild">
<Target Name="L10n" AfterTargets="BeforeBuild">
<L10nBuildTask/>
<ItemGroup>
<L10nLanguageFiles Include="$(SolutionDir)phrases.json;$(SolutionDir)language-*.json" />
<L10nLanguageFiles Include="$(SolutionDir)phrases.json;$(SolutionDir)languages.json;$(SolutionDir)language-*.json" />
</ItemGroup>
<Message Importance="high" Text="Copying phrase-files from @(L10nLanguageFiles) to $(ProjectDir)L10n\" />
<Copy SourceFiles="@(L10nLanguageFiles)" DestinationFolder="$(ProjectDir)L10n\" />
Expand Down
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MN.L10n [![Build status](https://ci.appveyor.com/api/projects/status/y5uh8gvxm29v90rk?svg=true)](https://ci.appveyor.com/project/itssimple/mn-l10n)
# MN.L10n [![Build status](https://ci.appveyor.com/api/projects/status/y5uh8gvxm29v90rk?svg=true)](https://ci.appveyor.com/project/itssimple/mn-l10n)
Translation-thingy for all our products

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

```javascript
DealDetails.ShowNotification(
_s('Sparade en ny notering på $companyName$',
_s('Sparade en ny notering på $companyName$',
{ companyName: DealDetails.DealInfo.CompanyName }
)
);
Expand Down Expand Up @@ -91,6 +91,47 @@ protected void Application_Start(object sender, EventArgs e)

---

# Example files

## languages.json

```json
[ "sv_SE", "en_GB" ]
```

## phrases.json

```json
{
Phrases: {
"Hello world": {
"Created": "2017-01-01T00:00:00.000Z",
"Usages": 1,
"Comment": "Standard phrase, found everywhere."
}
}
}
```

## language-sv_SE.json

```json
{
"LanguageName": "Svenska",
"Locale": "sv-SE",
"PluralizationRules": [ "0", "1" ],
"PluralRule": "(n != 1)",
"Phrases": {
"Hello world": {
"r": {
"0": "Hej världen"
}
}
}
}
```
---

#### Things we use in the code to make the magic happen
- [Glob.cs](https://github.com/mganss/Glob.cs)
- [CommonMark.NET](https://github.com/Knagis/CommonMark.NET)
Expand Down

0 comments on commit 0367402

Please sign in to comment.