Browse files

removing FubuLocalization from this repo

  • Loading branch information...
1 parent bebd632 commit 3ac96f1dfa763cc74e7ff4ee7cf21de01423cfdb @jeremydmiller jeremydmiller committed Mar 17, 2012
Showing with 1 addition and 3,072 deletions.
  1. +0 −25 packaging/nuget/fubulocalization.nuspec
  2. +1 −2 rakefile.rb
  3. +0 −49 src/FubuCore.sln
  4. +0 −154 src/FubuLocalization.Tests/Basic/AssemblyScannerTester.cs
  5. +0 −119 src/FubuLocalization.Tests/Basic/LocalizationMissingHandlerTester.cs
  6. +0 −133 src/FubuLocalization.Tests/Basic/LocalizationProviderFactoryIntegratedTester.cs
  7. +0 −97 src/FubuLocalization.Tests/FubuLocalization.Tests.csproj
  8. +0 −68 src/FubuLocalization.Tests/LocalStringTester.cs
  9. +0 −101 src/FubuLocalization.Tests/LocalizationManagerTester.cs
  10. +0 −36 src/FubuLocalization.Tests/Properties/AssemblyInfo.cs
  11. +0 −44 src/FubuLocalization.Tests/PropertyTokenTester.cs
  12. +0 −84 src/FubuLocalization.Tests/StringTokenTester.cs
  13. +0 −42 src/FubuLocalization.Tests/StringTokenToLocalizationKeyTester.cs
  14. +0 −61 src/FubuLocalization.Tests/ThreadSafeLocaleCacheTester.cs
  15. +0 −287 src/FubuLocalization.Tests/XmlDirectoryLocalizationStorageTester.cs
  16. +0 −56 src/FubuLocalization.Tests/fill_in_keys_on_string_token.cs
  17. +0 −6 src/FubuLocalization.Tests/packages.config
  18. +0 −76 src/FubuLocalization/Basic/AssemblyScanner.cs
  19. +0 −13 src/FubuLocalization/Basic/ILocalizationCache.cs
  20. +0 −12 src/FubuLocalization/Basic/ILocalizationProviderFactory.cs
  21. +0 −17 src/FubuLocalization/Basic/ILocalizationStorage.cs
  22. +0 −44 src/FubuLocalization/Basic/InMemoryLocalizationStorage.cs
  23. +0 −58 src/FubuLocalization/Basic/LocalizationCache.cs
  24. +0 −57 src/FubuLocalization/Basic/LocalizationMissingHandler.cs
  25. +0 −41 src/FubuLocalization/Basic/LocalizationProvider.cs
  26. +0 −51 src/FubuLocalization/Basic/LocalizationProviderFactory.cs
  27. +0 −210 src/FubuLocalization/Basic/XmlDirectoryLocalizationStorage.cs
  28. +0 −20 src/FubuLocalization/CurrentCultureContext.cs
  29. +0 −83 src/FubuLocalization/FubuLocalization.csproj
  30. +0 −30 src/FubuLocalization/HeaderTextAttribute.cs
  31. +0 −10 src/FubuLocalization/ICurrentCultureContext.cs
  32. +0 −12 src/FubuLocalization/ILocaleCache.cs
  33. +0 −7 src/FubuLocalization/ILocaleCacheContext.cs
  34. +0 −13 src/FubuLocalization/ILocalizationDataProvider.cs
  35. +0 −10 src/FubuLocalization/ILocalizationMissingHandler.cs
  36. +0 −105 src/FubuLocalization/LocalString.cs
  37. +0 −11 src/FubuLocalization/LocalizationExtensions.cs
  38. +0 −60 src/FubuLocalization/LocalizationKey.cs
  39. +0 −119 src/FubuLocalization/LocalizationManager.cs
  40. +0 −46 src/FubuLocalization/NulloLocalizationDataProvider.cs
  41. +0 −36 src/FubuLocalization/Properties/AssemblyInfo.cs
  42. +0 −132 src/FubuLocalization/PropertyToken.cs
  43. +0 −145 src/FubuLocalization/StringToken.cs
  44. +0 −64 src/FubuLocalization/ThreadSafeLocaleCache.cs
  45. +0 −73 src/localizer/FolderInput.cs
  46. +0 −42 src/localizer/Program.cs
  47. +0 −36 src/localizer/Properties/AssemblyInfo.cs
  48. +0 −3 src/localizer/app.config
  49. +0 −72 src/localizer/localizer.csproj
View
25 packaging/nuget/fubulocalization.nuspec
@@ -1,25 +0,0 @@
-<?xml version="1.0"?>
-<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
- <id>FubuLocalization</id>
- <version>0.0.0</version>
- <authors>Chad Myers, Jeremy D. Miller, Joshua Flanagan</authors>
- <owners>Jeremy D. Miller</owners>
- <licenseUrl>https://github.com/DarthFubuMVC/fubucore/raw/master/license.txt</licenseUrl>
- <projectUrl>http://localization.fubu-project.org</projectUrl>
- <iconUrl>https://github.com/DarthFubuMVC/fubu-collateral/raw/master/Icons/FubuLocalization_256.png</iconUrl>
- <requireLicenseAcceptance>false</requireLicenseAcceptance>
- <description>Localization utilities</description>
- <tags>utilities, fubu</tags>
- <dependencies>
- <dependency id="FubuCore"/>
- </dependencies>
- </metadata>
- <files>
- <file src="..\..\build\FubuLocalization.*" target="lib" />
- <file src="..\..\build\FubuLocalization.*" target="tools" />
- <file src="..\..\build\FubuCore.*" target="tools" />
- <file src="..\..\build\localizer.*" target="tools" />
- <file src="..\..\build\Microsoft.Practices.ServiceLocation.*" target="tools" />
- </files>
-</package>
View
3 rakefile.rb
@@ -76,7 +76,6 @@ def waitfor(&block)
task :compile => [:clean, :restore_if_missing, :version] do
MSBuildRunner.compile :compilemode => COMPILE_TARGET, :solutionfile => 'src/FubuCore.sln', :clrversion => CLR_TOOLS_VERSION
copyOutputFiles "src/FubuCore/bin/#{COMPILE_TARGET}", "Fubu*.{dll,pdb}", props[:stage]
- copyOutputFiles "src/FubuLocalization/bin/#{COMPILE_TARGET}", "FubuLocalization*.{dll,pdb}", props[:stage]
copyOutputFiles "src/localizer/bin/#{COMPILE_TARGET}", "localizer*.{exe,pdb}", props[:stage]
copyOutputFiles "src/localizer/bin/#{COMPILE_TARGET}", "Microsoft.Practices.ServiceLocation.dll", props[:stage]
copyOutputFiles "src/FubuTestingSupport/bin/#{COMPILE_TARGET}", "FubuTestingSupport*.{dll,pdb}", props[:stage]
@@ -94,5 +93,5 @@ def copyOutputFiles(fromDir, filePattern, outDir)
desc "Runs unit tests"
task :unit_test => :compile do
runner = NUnitRunner.new :compilemode => COMPILE_TARGET, :source => 'src', :platform => 'x86'
- runner.executeTests ['FubuCore.Testing', 'FubuLocalization.Tests']
+ runner.executeTests ['FubuCore.Testing']
end
View
49 src/FubuCore.sln
@@ -11,14 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FubuCore", "FubuCore\FubuCo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FubuCore.Testing", "FubuCore.Testing\FubuCore.Testing.csproj", "{F2F97121-B7E0-4435-8F38-47EB9B5C8E36}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FubuLocalization", "FubuLocalization\FubuLocalization.csproj", "{05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FubuLocalization.Tests", "FubuLocalization.Tests\FubuLocalization.Tests.csproj", "{AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FubuTestingSupport", "FubuTestingSupport\FubuTestingSupport.csproj", "{CEF04237-F832-4BAF-BA5F-C5DEA0635E8E}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "localizer", "localizer\localizer.csproj", "{13AC0846-4C06-4E5F-AB6B-6997CA5C578D}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -62,34 +56,6 @@ Global
{F2F97121-B7E0-4435-8F38-47EB9B5C8E36}.Retail|Mixed Platforms.ActiveCfg = Release|Any CPU
{F2F97121-B7E0-4435-8F38-47EB9B5C8E36}.Retail|Mixed Platforms.Build.0 = Release|Any CPU
{F2F97121-B7E0-4435-8F38-47EB9B5C8E36}.Retail|x86.ActiveCfg = Release|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Debug|x86.ActiveCfg = Debug|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Release|Any CPU.Build.0 = Release|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Release|x86.ActiveCfg = Release|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Retail|Any CPU.ActiveCfg = Release|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Retail|Any CPU.Build.0 = Release|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Retail|Mixed Platforms.ActiveCfg = Release|Any CPU
- {05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}.Retail|x86.ActiveCfg = Release|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Debug|x86.ActiveCfg = Debug|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Release|Any CPU.Build.0 = Release|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Release|x86.ActiveCfg = Release|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Retail|Any CPU.ActiveCfg = Release|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Retail|Any CPU.Build.0 = Release|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Retail|Mixed Platforms.ActiveCfg = Release|Any CPU
- {AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}.Retail|x86.ActiveCfg = Release|Any CPU
{CEF04237-F832-4BAF-BA5F-C5DEA0635E8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CEF04237-F832-4BAF-BA5F-C5DEA0635E8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEF04237-F832-4BAF-BA5F-C5DEA0635E8E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -105,21 +71,6 @@ Global
{CEF04237-F832-4BAF-BA5F-C5DEA0635E8E}.Retail|Mixed Platforms.ActiveCfg = Release|Any CPU
{CEF04237-F832-4BAF-BA5F-C5DEA0635E8E}.Retail|Mixed Platforms.Build.0 = Release|Any CPU
{CEF04237-F832-4BAF-BA5F-C5DEA0635E8E}.Retail|x86.ActiveCfg = Release|Any CPU
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Debug|Any CPU.ActiveCfg = Debug|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Debug|Mixed Platforms.Build.0 = Debug|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Debug|x86.ActiveCfg = Debug|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Debug|x86.Build.0 = Debug|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Release|Any CPU.ActiveCfg = Release|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Release|Mixed Platforms.ActiveCfg = Release|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Release|Mixed Platforms.Build.0 = Release|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Release|x86.ActiveCfg = Release|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Release|x86.Build.0 = Release|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Retail|Any CPU.ActiveCfg = Release|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Retail|Mixed Platforms.ActiveCfg = Release|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Retail|Mixed Platforms.Build.0 = Release|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Retail|x86.ActiveCfg = Release|x86
- {13AC0846-4C06-4E5F-AB6B-6997CA5C578D}.Retail|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
154 src/FubuLocalization.Tests/Basic/AssemblyScannerTester.cs
@@ -1,154 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Reflection;
-using FubuCore.Reflection;
-using FubuLocalization.Basic;
-using NUnit.Framework;
-using FubuTestingSupport;
-
-namespace FubuLocalization.Tests.Basic
-{
- [TestFixture]
- public class AssemblyScannerTester
- {
- private InMemoryLocalizationStorage theStorage;
- private AssemblyScanner theScanner;
- private CultureInfo theCulture;
-
- [SetUp]
- public void SetUp()
- {
- theCulture = new CultureInfo("en-GB");
- theStorage = new InMemoryLocalizationStorage();
- theScanner = new AssemblyScanner(theStorage, theCulture);
-
-
-
- }
-
- [Test]
- public void the_default_culture_should_be_en_US()
- {
- theScanner.DefaultCulture.ShouldEqual(new CultureInfo("en-US"));
- }
-
- [Test]
- public void scan_string_token_class_that_is_all_missing_and_for_the_default_culture()
- {
- theScanner.DefaultCulture = theCulture;
-
- theScanner.ScanStringTokenType(typeof(AssemblyScannerTokens));
-
- theStorage.RecordedMissingKeysFor(theCulture).ShouldHaveTheSameElementsAs(LocalString.ReadAllFrom(@"
- A=a
- B=b
- C=c
- D=d
-"));
- }
-
-
- [Test]
- public void scan_string_token_class_that_is_all_missing_for_a_different_culture_than_the_default()
- {
- theScanner.ScanStringTokenType(typeof(AssemblyScannerTokens));
-
- theStorage.RecordedMissingKeysFor(theCulture).ShouldHaveTheSameElementsAs(LocalString.ReadAllFrom(@"
- A=en-GB_A
- B=en-GB_B
- C=en-GB_C
- D=en-GB_D
-"));
- }
-
- [Test]
- public void scan_string_token_class_when_some_are_not_missing()
- {
- theStorage.Add(theCulture, "A", "a-something");
- theStorage.Add(theCulture, "C", "c-something");
-
- theScanner.DefaultCulture = theCulture;
-
- theScanner.ScanStringTokenType(typeof(AssemblyScannerTokens));
-
- theStorage.RecordedMissingKeysFor(theCulture).ShouldHaveTheSameElementsAs(LocalString.ReadAllFrom(@"
- B=b
- D=d
-"));
- }
-
- [Test]
- public void scan_using_a_localized_property_implementation()
- {
- theScanner.DefaultCulture = theCulture;
-
- theScanner.ScanProperties(new ScanningPolicy());
-
- theStorage.RecordedMissingKeysFor(theCulture).ShouldHaveTheSameElementsAs(LocalString.ReadAllFrom(@"
- FubuLocalization.Tests.Basic.AssemblyScannerTester+ScanningTarget:Name:Header=Name
- FubuLocalization.Tests.Basic.AssemblyScannerTester+ScanningTarget:Title:Header=Title
- FubuLocalization.Tests.Basic.AssemblyScannerTester+ScanningTarget:Color:Header=Color
- X=x
- Y=y
- Z=z
-"));
- }
-
- [Test, Ignore("Need to update the expectation a bit, or filter")]
- public void scan_an_assembly()
- {
- theScanner.DefaultCulture = theCulture;
- theScanner.ScanAssembly(GetType().Assembly);
-
- theStorage.RecordedMissingKeysFor(theCulture).ShouldHaveTheSameElementsAs(LocalString.ReadAllFrom(@"
- A=a
- B=b
- C=c
- D=d
- FubuLocalization.Tests.Basic.AssemblyScannerTester+ScanningTarget:Name:Header=Name
- FubuLocalization.Tests.Basic.AssemblyScannerTester+ScanningTarget:Title:Header=Title
- FubuLocalization.Tests.Basic.AssemblyScannerTester+ScanningTarget:Color:Header=Color
- X=x
- Y=y
- Z=z
-"));
- }
-
- public class ScanningPolicy : ILocalizedProperties
- {
- public IEnumerable<PropertyInfo> FindProperties()
- {
- yield return ReflectionHelper.GetProperty<ScanningTarget>(x => x.Name);
- yield return ReflectionHelper.GetProperty<ScanningTarget>(x => x.Title);
- yield return ReflectionHelper.GetProperty<ScanningTarget>(x => x.Color);
- }
-
- public IEnumerable<StringToken> FindTokens()
- {
- yield return StringToken.FromKeyString("X", "x");
- yield return StringToken.FromKeyString("Y", "y");
- yield return StringToken.FromKeyString("Z", "z");
- }
- }
-
- public class ScanningTarget
- {
- public string Name { get; set; }
- public string Title { get; set; }
- public string Color { get; set; }
- }
- }
-
- public class AssemblyScannerTokens : StringToken
- {
- protected AssemblyScannerTokens(string key, string defaultValue) : base(key, defaultValue)
- {
- }
-
- public static readonly StringToken A = FromKeyString("A", "a");
- public static readonly StringToken B = FromKeyString("B", "b");
- public static readonly StringToken C = FromKeyString("C", "c");
- public static readonly StringToken D = FromKeyString("D", "d");
- }
-}
View
119 src/FubuLocalization.Tests/Basic/LocalizationMissingHandlerTester.cs
@@ -1,119 +0,0 @@
-using System;
-using System.Globalization;
-using System.Linq.Expressions;
-using FubuCore.Reflection;
-using FubuLocalization.Basic;
-using FubuTestingSupport;
-using NUnit.Framework;
-using Rhino.Mocks;
-using FubuCore;
-
-namespace FubuLocalization.Tests.Basic
-{
- [TestFixture]
- public class LocalizationMissingHandlerTester : InteractionContext<LocalizationMissingHandler>
- {
- private CultureInfo theDefaultCulture = new CultureInfo("en-US");
-
- protected override void beforeEach()
- {
- Services.Inject(theDefaultCulture);
- }
-
- [Test]
- public void find_missing_text_if_the_key_has_default_text_and_it_is_the_default_culture()
- {
- var token = StringToken.FromKeyString("KEY1", "the default text");
-
- ClassUnderTest.FindMissingText(token, theDefaultCulture).ShouldEqual("the default text");
-
- MockFor<ILocalizationStorage>().AssertWasCalled(x => x.WriteMissing("KEY1", "the default text", theDefaultCulture));
- }
-
- [Test]
- public void find_missing_text_if_the_key_does_not_have_default_text_and_it_is_the_default_culture()
- {
- var token = StringToken.FromKeyString("KEY1");
-
- ClassUnderTest.FindMissingText(token, theDefaultCulture).ShouldEqual("en-US_KEY1");
-
- MockFor<ILocalizationStorage>().AssertWasCalled(x => x.WriteMissing("KEY1", "en-US_KEY1", theDefaultCulture));
- }
-
- [Test]
- public void find_missing_text_if_the_key_has_default_text_but_it_is_not_the_default_culture()
- {
- var token = StringToken.FromKeyString("KEY1", "the default text");
-
- var cultureInfo = new CultureInfo("fr-FR");
- ClassUnderTest.FindMissingText(token, cultureInfo)
- .ShouldEqual("fr-FR_KEY1");
-
- MockFor<ILocalizationStorage>().AssertWasCalled(x => x.WriteMissing("KEY1", "fr-FR_KEY1", cultureInfo));
- }
-
- private string findMissingProperty(Expression<Func<MissingHandlerTarget, object>> expression, CultureInfo culture)
- {
- var propertyInfo = ReflectionHelper.GetProperty(expression);
- return ClassUnderTest.FindMissingProperty(new PropertyToken(propertyInfo), culture);
- }
-
- [Test]
- public void find_missing_property_with_no_header_attribute_and_the_default_culture()
- {
- findMissingProperty(x => x.Name, theDefaultCulture).ShouldEqual("Name");
- }
-
- [Test]
- public void find_missing_property_with_no_header_attribute_and_non_default_culture()
- {
- findMissingProperty(x => x.Name, new CultureInfo("fr-FR")).ShouldEqual("fr-FR_Name");
- }
-
- [Test]
- public void find_missing_property_with_header_attribute_that_is_not_marked_by_culture_and_default_culture()
- {
- findMissingProperty(x => x.Title, theDefaultCulture).ShouldEqual("The title");
- }
-
- [Test]
- public void find_missing_property_with_header_attribute_that_is_not_marked_by_culture_and_a_non_default_culture()
- {
- findMissingProperty(x => x.Title, new CultureInfo("fr-FR")).ShouldEqual("fr-FR_Title");
- }
-
- [Test]
- public void find_missing_property_with_header_attribute_that_matches_the_culture()
- {
- findMissingProperty(x => x.AnotherTitle, new CultureInfo("en-GB")).ShouldEqual("Other title");
- }
-
- [Test]
- public void find_missing_property_with_header_attribute_that_does_not_match_the_culture()
- {
- findMissingProperty(x => x.AnotherTitle, theDefaultCulture).ShouldEqual("Another Title");
- }
-
- [Test]
- public void should_write_the_missing_property_value_to_storage()
- {
- var defaultValue = findMissingProperty(x => x.Name, theDefaultCulture);
-
-
- var key = "{0}:Name:Header".ToFormat(typeof (MissingHandlerTarget).FullName);
-
- MockFor<ILocalizationStorage>().AssertWasCalled(x => x.WriteMissing(key, defaultValue, theDefaultCulture));
- }
- }
-
- public class MissingHandlerTarget
- {
- public string Name { get; set; }
-
- [HeaderText("The title")]
- public string Title { get; set; }
-
- [HeaderText("Other title", Culture = "en-GB")]
- public string AnotherTitle { get; set;}
- }
-}
View
133 src/FubuLocalization.Tests/Basic/LocalizationProviderFactoryIntegratedTester.cs
@@ -1,133 +0,0 @@
-using System.Globalization;
-using System.Threading;
-using FubuCore;
-using FubuLocalization.Basic;
-using FubuTestingSupport;
-using NUnit.Framework;
-
-namespace FubuLocalization.Tests.Basic
-{
- [TestFixture]
- public class LocalizationProviderFactoryIntegratedTester
- {
- [SetUp]
- public void SetUp()
- {
- var system = new FileSystem();
- system.DeleteDirectory("localization1");
- system.DeleteDirectory("localization2");
- system.DeleteDirectory("localization3");
-
- system.CreateDirectory("localization1");
- system.CreateDirectory("localization2");
- system.CreateDirectory("localization3");
- }
-
- // values = "value=display"
- private void write(string directory, CultureInfo culture, string values)
- {
- XmlDirectoryLocalizationStorage.Write(directory, culture, LocalString.ReadAllFrom(values));
- }
-
- [Test]
- public void load_all()
- {
- write("localization1", new CultureInfo("en-US"),
- @"
- a=us-a
- b=us-b
- f=us-f
- ");
-
- write("localization2", new CultureInfo("en-US"),
- @"
- c=us-c
- d=us-d
- ");
-
- write("localization3", new CultureInfo("en-US"), @"
- e=us-e
- ");
-
- write("localization1", new CultureInfo("en-GB"),
- @"
- a=gb-a
- b=gb-b
- f=gb-f
- ");
-
- write("localization2", new CultureInfo("en-GB"),
- @"
- c=gb-c
- d=gb-d
- ");
-
-
- var source = new XmlDirectoryLocalizationStorage(new[]{"localization1", "localization2", "localization3"});
- var factory = new LocalizationProviderFactory(source, null, new LocalizationCache());
- factory.LoadAll(x => { });
-
- factory.BuildProvider(new CultureInfo("en-US"))
- .GetTextForKey(StringToken.FromKeyString("a"))
- .ShouldEqual("us-a");
-
- factory.BuildProvider(new CultureInfo("en-US"))
- .GetTextForKey(StringToken.FromKeyString("e"))
- .ShouldEqual("us-e");
-
- factory.BuildProvider(new CultureInfo("en-GB"))
- .GetTextForKey(StringToken.FromKeyString("a"))
- .ShouldEqual("gb-a");
- }
-
- [Test]
- public void put_it_all_together()
- {
- write("localization1", new CultureInfo("en-US"),
- @"
- a=us-a
- b=us-b
- f=us-f
- ");
-
- write("localization2", new CultureInfo("en-US"),
- @"
- c=us-c
- d=us-d
- ");
-
- write("localization3", new CultureInfo("en-US"), @"
- e=us-e
- ");
-
- write("localization1", new CultureInfo("en-GB"),
- @"
- a=gb-a
- b=gb-b
- f=gb-f
- ");
-
- write("localization2", new CultureInfo("en-GB"),
- @"
- c=gb-c
- d=gb-d
- ");
-
-
- var source = new XmlDirectoryLocalizationStorage(new[] { "localization1", "localization2", "localization3" });
- var factory = new LocalizationProviderFactory(source, new LocalizationMissingHandler(source, new CultureInfo("en-US")), new LocalizationCache());
- factory.LoadAll(x => { });
- factory.ApplyToLocalizationManager();
-
- var token = StringToken.FromKeyString("a", "Wrong!");
-
- Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
-
- token.ToString().ShouldEqual("us-a");
-
- Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
-
- token.ToString().ShouldEqual("gb-a");
- }
- }
-}
View
97 src/FubuLocalization.Tests/FubuLocalization.Tests.csproj
@@ -1,97 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.30703</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{AFD1AFE7-0B3E-4087-ABF8-73B7E212D320}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>FubuLocalization.Tests</RootNamespace>
- <AssemblyName>FubuLocalization.Tests</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="nunit.framework">
- <HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath>
- </Reference>
- <Reference Include="nunit.mocks">
- <HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.mocks.dll</HintPath>
- </Reference>
- <Reference Include="pnunit.framework">
- <HintPath>..\packages\NUnit.2.5.10.11092\lib\pnunit.framework.dll</HintPath>
- </Reference>
- <Reference Include="Rhino.Mocks">
- <HintPath>..\packages\RhinoMocks.3.6\lib\Rhino.Mocks.dll</HintPath>
- </Reference>
- <Reference Include="StructureMap">
- <HintPath>..\packages\structuremap.2.6.3\lib\StructureMap.dll</HintPath>
- </Reference>
- <Reference Include="StructureMap.AutoMocking, Version=2.6.3.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223, processorArchitecture=MSIL" />
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="Microsoft.CSharp" />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Basic\AssemblyScannerTester.cs" />
- <Compile Include="Basic\LocalizationMissingHandlerTester.cs" />
- <Compile Include="Basic\LocalizationProviderFactoryIntegratedTester.cs" />
- <Compile Include="fill_in_keys_on_string_token.cs" />
- <Compile Include="LocalizationManagerTester.cs" />
- <Compile Include="LocalStringTester.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="PropertyTokenTester.cs" />
- <Compile Include="StringTokenTester.cs" />
- <Compile Include="StringTokenToLocalizationKeyTester.cs" />
- <Compile Include="ThreadSafeLocaleCacheTester.cs" />
- <Compile Include="XmlDirectoryLocalizationStorageTester.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\FubuCore\FubuCore.csproj">
- <Project>{342B987C-E0A4-4129-958D-8E08084E8A06}</Project>
- <Name>FubuCore</Name>
- </ProjectReference>
- <ProjectReference Include="..\FubuLocalization\FubuLocalization.csproj">
- <Project>{05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}</Project>
- <Name>FubuLocalization</Name>
- </ProjectReference>
- <ProjectReference Include="..\FubuTestingSupport\FubuTestingSupport.csproj">
- <Project>{CEF04237-F832-4BAF-BA5F-C5DEA0635E8E}</Project>
- <Name>FubuTestingSupport</Name>
- </ProjectReference>
- </ItemGroup>
- <ItemGroup>
- <None Include="packages.config" />
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
View
68 src/FubuLocalization.Tests/LocalStringTester.cs
@@ -1,68 +0,0 @@
-using System;
-using System.Collections.Generic;
-using FubuTestingSupport;
-using NUnit.Framework;
-
-namespace FubuLocalization.Tests
-{
- [TestFixture]
- public class LocalStringTester
- {
- [Test]
- public void two_instances_with_the_same_key_should_equal_each_other()
- {
- var x = new LocalString { value = "foo" };
- var y = new LocalString { value = "foo" };
-
- x.ShouldEqual(y);
- y.ShouldEqual(x);
- }
-
- [Test]
- public void two_instances_with_the_same_key_should_be_considered_the_same_for_hashing_purposes()
- {
- var x = new LocalString { value = "foo" };
- var y = new LocalString { value = "foo" };
-
- var dict = new Dictionary<LocalString, int> { { x, 0 } };
-
- dict.ContainsKey(y).ShouldBeTrue();
- }
-
- [Test]
- public void read_from_happy_path()
- {
- LocalString.ReadFrom("key=foo").ShouldEqual(new LocalString("key", "foo"));
-
- }
-
-
- [Test]
- public void read_from_happy_path_trims()
- {
- LocalString.ReadFrom(" key=foo ").ShouldEqual(new LocalString("key", "foo"));
-
- }
-
- [Test]
- public void read_from_sad_path_fails_with_descriptive_error()
- {
- Exception<ArgumentException>.ShouldBeThrownBy(() =>
- {
- LocalString.ReadFrom("key:foo");
- }).Message.ShouldEqual("LocalString must be expressed as 'value=display', 'key:foo' is invalid");
-
-
- }
-
- [Test]
- public void read_all()
- {
- LocalString.ReadAllFrom(@"
-a=a-display
-b=b-display
-c=c-display
-").ShouldHaveTheSameElementsAs(new LocalString("a", "a-display"), new LocalString("b", "b-display"), new LocalString("c", "c-display"));
- }
- }
-}
View
101 src/FubuLocalization.Tests/LocalizationManagerTester.cs
@@ -1,101 +0,0 @@
-using System.Reflection;
-using FubuCore.Reflection;
-using FubuTestingSupport;
-using NUnit.Framework;
-using Rhino.Mocks;
-
-namespace FubuLocalization.Tests
-{
- [TestFixture]
- public class LocalizationManagerTester
- {
- private MockRepository _mocks;
- private ILocalizationDataProvider _provider;
-
- [SetUp]
- public void SetUp()
- {
- _mocks = new MockRepository();
- _provider = _mocks.StrictMock<ILocalizationDataProvider>();
-
- LocalizationManager.Stub(_provider);
- }
-
- [TearDown]
- public void TearDown()
- {
- LocalizationManager.Stub();
- }
-
- [Test]
- public void GetText_for_property()
- {
- PropertyInfo property = ReflectionHelper.GetProperty<DummyEntity>(c => c.SimpleProperty);
-
- using (_mocks.Record())
- {
- Expect.Call(_provider.GetHeader(property)).Return("TheText");
- }
-
- using (_mocks.Playback())
- {
- LocalizationManager.GetText(property).ShouldEqual("TheText");
- }
- }
-
- [Test]
- public void GetText_for_property_by_expression()
- {
- PropertyInfo property = ReflectionHelper.GetProperty<DummyEntity>(c => c.SimpleProperty);
-
- using (_mocks.Record())
- {
- Expect.Call(_provider.GetHeader(property)).Return("TheText");
- }
-
- using (_mocks.Playback())
- {
- LocalizationManager.GetText<DummyEntity>(c => c.SimpleProperty).ShouldEqual("TheText");
- }
- }
-
- [Test]
- public void GetHeader_for_property()
- {
- PropertyInfo property = ReflectionHelper.GetProperty<DummyEntity>(c => c.SimpleProperty);
- var theHeader = "TheText";
-
- using (_mocks.Record())
- {
- Expect.Call(_provider.GetHeader(property)).Return(theHeader);
- }
-
- using (_mocks.Playback())
- {
- LocalizationManager.GetHeader(property).ShouldEqual(theHeader);
- }
- }
-
- [Test]
- public void GetHeader_for_property_by_expression()
- {
- PropertyInfo property = ReflectionHelper.GetProperty<DummyEntity>(c => c.SimpleProperty);
- var theHeader = "TheText";
-
- using (_mocks.Record())
- {
- Expect.Call(_provider.GetHeader(property)).Return(theHeader);
- }
-
- using (_mocks.Playback())
- {
- LocalizationManager.GetHeader<DummyEntity>(c => c.SimpleProperty).ShouldEqual(theHeader);
- }
- }
-
- public class DummyEntity
- {
- public string SimpleProperty { get; set; }
- }
- }
-}
View
36 src/FubuLocalization.Tests/Properties/AssemblyInfo.cs
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("FubuLocalization.Tests")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Microsoft")]
-[assembly: AssemblyProduct("FubuLocalization.Tests")]
-[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("53f8838d-59a3-4b59-95bd-88bf78e2db6d")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
View
44 src/FubuLocalization.Tests/PropertyTokenTester.cs
@@ -1,44 +0,0 @@
-using System.Globalization;
-using FubuTestingSupport;
-using NUnit.Framework;
-
-namespace FubuLocalization.Tests
-{
- [TestFixture]
- public class PropertyTokenTester
- {
- [Test]
- public void find_default_header_for_the_attribute()
- {
- var token = new PropertyToken
- {
- ParentType = typeof(PropertyTokenTarget),
- PropertyName = "Name"
- };
-
- token.FindDefaultHeader(new CultureInfo("en-US")).ShouldEqual("The Name");
- token.FindDefaultHeader(new CultureInfo("en-CA")).ShouldEqual("Different");
- token.FindDefaultHeader(new CultureInfo("ja-JP")).ShouldBeNull();
- }
-
- [Test]
- public void find_default_header_for_property_that_is_not_decorated_should_just_return_null()
- {
- var token = new PropertyToken
- {
- ParentType = typeof(PropertyTokenTarget),
- PropertyName = "NotDecorated"
- };
-
- token.FindDefaultHeader(new CultureInfo("en-US")).ShouldBeNull();
- }
- }
-
- public class PropertyTokenTarget
- {
- [HeaderText("The Name"), HeaderText("Different", Culture = "en-CA")]
- public string Name { get; set; }
-
- public string NotDecorated { get; set; }
- }
-}
View
84 src/FubuLocalization.Tests/StringTokenTester.cs
@@ -1,84 +0,0 @@
-using System.Collections.Generic;
-using FubuTestingSupport;
-using NUnit.Framework;
-using Rhino.Mocks;
-
-namespace FubuLocalization.Tests
-{
- [TestFixture]
- public class StringTokenTester
- {
- [Test]
- public void from_type_just_uses_type_name()
- {
- var token = StringToken.FromType<StringTokenTester>();
- token.Key.ShouldEqual(GetType().Name);
- token.DefaultValue.ShouldEqual(GetType().Name);
- }
-
- [Test]
- public void from_type_just_uses_type_name_2()
- {
- var token = StringToken.FromType(GetType());
- token.Key.ShouldEqual(GetType().Name);
- token.DefaultValue.ShouldEqual(GetType().Name);
- }
-
- [Test]
- public void two_instances_with_the_same_key_should_equal_equal_each_other()
- {
- var x = buildCommonToken();
- var y = buildCommonToken();
-
- x.ShouldEqual(y);
- }
-
- [Test]
- public void two_instances_with_the_same_key_should_be_considered_the_same_for_hashing_purposes()
- {
- var x = buildCommonToken();
- var y = buildCommonToken();
-
- var dict = new Dictionary<StringToken, int> { { x, 0 } };
-
- dict.ContainsKey(y).ShouldBeTrue();
- }
-
- [Test]
- public void should_render_to_string_from_localization_when_condition_is_true()
- {
- var mocks = new MockRepository();
- var provider = mocks.StrictMock<ILocalizationDataProvider>();
- var token = buildCommonToken();
- const string retVal = "TheText";
-
- LocalizationManager.Stub(provider);
-
- using (mocks.Record())
- {
- Expect.Call(provider.GetTextForKey(token)).Return(retVal);
- }
-
- using (mocks.Playback())
- {
- token
- .ToString(true)
- .ShouldEqual(retVal);
- }
- }
-
- [Test]
- public void should_render_to_string_as_empty_when_condition_is_false()
- {
- buildCommonToken()
- .ToString(false)
- .ShouldEqual(string.Empty);
- }
-
- private StringToken buildCommonToken()
- {
- const string key = "test";
- return StringToken.FromKeyString(key, "default");
- }
- }
-}
View
42 src/FubuLocalization.Tests/StringTokenToLocalizationKeyTester.cs
@@ -1,42 +0,0 @@
-using System;
-using NUnit.Framework;
-using FubuTestingSupport;
-
-namespace FubuLocalization.Tests
-{
- [TestFixture]
- public class StringTokenToLocalizationKeyTester
- {
- [Test]
- public void localization_key_includes_the_namespace_if_it_exists()
- {
- NoNamespaceStringToken.Key1.ToLocalizationKey().Key1.ShouldEqual("Key1");
- }
-
- [Test]
- public void localization_key_with_namespace()
- {
- StringTokenWithNamespace.Key1.ToLocalizationKey().Key1.ShouldEqual("NS1:Key1");
- }
- }
-
- public class NoNamespaceStringToken : StringToken
- {
- public static readonly StringToken Key1 = new NoNamespaceStringToken("Key1", "something");
-
- protected NoNamespaceStringToken(string key, string defaultValue) : base(key, defaultValue)
- {
-
- }
- }
-
- public class StringTokenWithNamespace : FubuLocalization.StringToken
- {
- public static readonly StringToken Key1 = new StringTokenWithNamespace("Key1", "something");
-
- protected StringTokenWithNamespace(string key, string defaultValue) : base(key, defaultValue, "NS1")
- {
-
- }
- }
-}
View
61 src/FubuLocalization.Tests/ThreadSafeLocaleCacheTester.cs
@@ -1,61 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using FubuTestingSupport;
-using NUnit.Framework;
-
-namespace FubuLocalization.Tests
-{
- [TestFixture]
- public class ThreadSafeLocaleCacheTester
- {
- private ThreadSafeLocaleCache cache;
-
- [SetUp]
- public void SetUp()
- {
- var dictionary = new Dictionary<LocalizationKey, string>()
- {
- {new LocalizationKey("a"), "a1"},
- {new LocalizationKey("b"), "b1"},
- {new LocalizationKey("c"), "c1"},
- };
-
- cache = new ThreadSafeLocaleCache(new CultureInfo("en-US"), dictionary);
- }
-
- [Test]
- public void retrieve_a_key_that_can_be_found()
- {
- cache.Retrieve(new LocalizationKey("a"), () =>
- {
- throw new AccessViolationException("Shouldn't call this");
- })
- .ShouldEqual("a1");
- }
-
- [Test]
- public void append_and_retrieve()
- {
- cache.Append(new LocalizationKey("d"), "d1");
- cache.Retrieve(new LocalizationKey("d"), () =>
- {
- throw new AccessViolationException("Shouldn't call this");
- })
- .ShouldEqual("d1");
- }
-
- [Test]
- public void call_the_missing_function_if_the_key_cannot_be_found()
- {
- cache.Retrieve(new LocalizationKey("d"), () => "d1").ShouldEqual("d1");
-
- // call again should hit the cache
- cache.Retrieve(new LocalizationKey("d"), () =>
- {
- throw new AccessViolationException("Shouldn't call this");
- })
- .ShouldEqual("d1");
- }
- }
-}
View
287 src/FubuLocalization.Tests/XmlDirectoryLocalizationStorageTester.cs
@@ -1,287 +0,0 @@
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-using System.Xml;
-using FubuCore;
-using System.Collections.Generic;
-using FubuCore.Util;
-using FubuLocalization.Basic;
-using NUnit.Framework;
-using FubuTestingSupport;
-using System.Linq;
-using FubuCore.Configuration;
-
-namespace FubuLocalization.Tests
-{
- [TestFixture]
- public class XmlDirectoryLocalizationStorageTester
- {
- [SetUp]
- public void SetUp()
- {
- var system = new FileSystem();
- system.DeleteDirectory("localization1");
- system.DeleteDirectory("localization2");
- system.DeleteDirectory("localization3");
-
- system.CreateDirectory("localization1");
- system.CreateDirectory("localization2");
- system.CreateDirectory("localization3");
- }
-
- // values = "value=display"
- private void write(string directory, CultureInfo culture, string values)
- {
- XmlDirectoryLocalizationStorage.Write(directory, culture, LocalString.ReadAllFrom(values));
- }
-
- [Test]
- public void GetFileName()
- {
- XmlDirectoryLocalizationStorage.GetFileName(new CultureInfo("en-US"))
- .ShouldEqual("en-US.locale.config");
-
- XmlDirectoryLocalizationStorage.GetFileName(new CultureInfo("en-GB"))
- .ShouldEqual("en-GB.locale.config");
- }
-
- [Test]
- public void save_and_load_local_strings()
- {
- var strings = new List<LocalString>{
- new LocalString("a", "a-display"),
- new LocalString("b", "b-display"),
- new LocalString("c", "c-display"),
- new LocalString("d", "d-display"),
- };
-
- XmlDirectoryLocalizationStorage.Write("locale.xml", strings);
-
- XmlDirectoryLocalizationStorage.LoadFrom("locale.xml").ShouldHaveTheSameElementsAs(strings);
- }
-
- [Test]
- public void save_and_load_local_strings_should_sort_on_key_for_easier_merges()
- {
- var strings = new List<LocalString>{
- new LocalString("c", "c-display"),
- new LocalString("d", "d-display"),
- new LocalString("a", "a-display"),
- new LocalString("b", "b-display"),
- };
-
- XmlDirectoryLocalizationStorage.Write("locale.xml", strings);
-
- XmlDirectoryLocalizationStorage.LoadFrom("locale.xml").ShouldHaveTheSameElementsAs(strings.OrderBy(x => x.value));
- }
-
- [Test]
- public void load_from_a_single_source()
- {
- write("localization1", new CultureInfo("en-US"), @"
- a=us-a
- b=us-b
- c=us-c
-");
-
- write("localization1", new CultureInfo("en-GB"), @"
- a=gb-a
- b=gb-b
- c=gb-c
-");
-
- var source = new XmlDirectoryLocalizationStorage(new string[]{"localization1"});
-
- source.Load(new CultureInfo("en-US")).ShouldHaveTheSameElementsAs(
- new LocalString("a", "us-a"),
- new LocalString("b", "us-b"),
- new LocalString("c", "us-c")
- );
-
- source.Load(new CultureInfo("en-GB")).ShouldHaveTheSameElementsAs(
- new LocalString("a", "gb-a"),
- new LocalString("b", "gb-b"),
- new LocalString("c", "gb-c")
- );
-
- }
-
- [Test]
- public void load_from_a_multiple_directory()
- {
- write("localization1", new CultureInfo("en-US"), @"
- a=us-a
- b=us-b
- c=us-c
-");
-
- write("localization2", new CultureInfo("en-US"), @"
- d=us-d
- e=us-e
-");
-
- var source = new XmlDirectoryLocalizationStorage(new string[] { "localization1", "localization2", "localization3" });
-
- source.Load(new CultureInfo("en-US")).ShouldHaveTheSameElementsAs(
- new LocalString("a", "us-a"),
- new LocalString("b", "us-b"),
- new LocalString("c", "us-c"),
- new LocalString("d", "us-d"),
- new LocalString("e", "us-e")
- );
-
- }
-
- [Test]
- public void write_missing_with_no_file_there()
- {
- var source = new XmlDirectoryLocalizationStorage(new string[] { "localization1", "localization2", "localization3" });
-
- source.WriteMissing("a", "us-a", new CultureInfo("en-US"));
-
- var document = new XmlDocument()
- .FromFile("localization1".AppendPath(XmlDirectoryLocalizationStorage.MissingLocaleConfigFile));
-
- var element = document.DocumentElement.FirstChild.As<XmlElement>();
- element.GetAttribute("culture").ShouldEqual("en-US");
- element.GetAttribute("key").ShouldEqual("a");
- element.InnerText.ShouldEqual("us-a");
-
-
- }
-
- [Test]
- public void write_with_successive_missings()
- {
- var source = new XmlDirectoryLocalizationStorage(new string[] { "localization1", "localization2", "localization3" });
-
- source.WriteMissing("a", "us-a", new CultureInfo("en-US"));
- source.WriteMissing("b", "us-b", new CultureInfo("en-US"));
-
- var document = new XmlDocument()
- .FromFile("localization1".AppendPath(XmlDirectoryLocalizationStorage.MissingLocaleConfigFile));
-
- var element = document.DocumentElement.LastChild.As<XmlElement>();
- element.GetAttribute("culture").ShouldEqual("en-US");
- element.GetAttribute("key").ShouldEqual("b");
- element.InnerText.ShouldEqual("us-b");
- }
-
- [Test]
- public void do_not_double_dip_in_missing_when_writing()
- {
- var source = new XmlDirectoryLocalizationStorage(new string[] { "localization1", "localization2", "localization3" });
-
- source.WriteMissing("a", "us-a", new CultureInfo("en-US"));
- source.WriteMissing("a", "us-a", new CultureInfo("en-US"));
- source.WriteMissing("a", "us-a", new CultureInfo("en-US"));
- source.WriteMissing("a", "us-a", new CultureInfo("en-US"));
- source.WriteMissing("a", "us-a", new CultureInfo("en-US"));
-
- var document = new XmlDocument()
- .FromFile("localization1".AppendPath(XmlDirectoryLocalizationStorage.MissingLocaleConfigFile));
-
- document.DocumentElement.ChildNodes.Count.ShouldEqual(1);
- }
-
- [Test]
- public void CultureFor()
- {
- XmlDirectoryLocalizationStorage.CultureFor("en-US.locale.config").ShouldEqual(new CultureInfo("en-US"));
- XmlDirectoryLocalizationStorage.CultureFor("en-CA.locale.config").ShouldEqual(new CultureInfo("en-CA"));
- XmlDirectoryLocalizationStorage.CultureFor("en-GB.locale.config").ShouldEqual(new CultureInfo("en-GB"));
- }
-
- [Test]
- public void load_all()
- {
- write("localization1", new CultureInfo("en-US"), @"
- a=us-a
- b=us-b
- f=us-f
- ");
-
- write("localization2", new CultureInfo("en-US"), @"
- c=us-c
- d=us-d
- ");
-
- write("localization3", new CultureInfo("en-US"), @"
- e=us-e
- ");
-
- write("localization1", new CultureInfo("en-GB"), @"
- a=gb-a
- b=gb-b
- f=gb-f
- ");
-
- write("localization2", new CultureInfo("en-GB"), @"
- c=gb-c
- d=gb-d
- ");
-
- var allKeys = new Cache<string, IList<LocalString>>(key => new List<LocalString>());
-
- var source = new XmlDirectoryLocalizationStorage(new string[] { "localization1", "localization2", "localization3" });
-
- source.LoadAll(text => Debug.WriteLine(text), (c, strings) => allKeys[c.Name].AddRange(strings));
-
- allKeys["en-US"].ShouldHaveTheSameElementsAs(LocalString.ReadAllFrom(@"
- a=us-a
- b=us-b
- f=us-f
- c=us-c
- d=us-d
- e=us-e
-"));
-
- allKeys["en-GB"].ShouldHaveTheSameElementsAs(LocalString.ReadAllFrom(@"
- a=gb-a
- b=gb-b
- f=gb-f
- c=gb-c
- d=gb-d
-"));
-
- }
-
-
-
- [Test]
- public void merge_missing()
- {
- var source = new XmlDirectoryLocalizationStorage(new string[] { "localization1", "localization2", "localization3" });
-
- write("localization1", new CultureInfo("en-US"), @"
- a=us-a
- b=us-b
- f=us-f
-");
-
- source.WriteMissing("c", "us-c", new CultureInfo("en-US"));
- source.WriteMissing("d", "us-d", new CultureInfo("en-US"));
- source.WriteMissing("a", "gb-A", new CultureInfo("en-GB"));
-
- source.MergeAllMissing();
-
- source.Load(new CultureInfo("en-US")).ShouldHaveTheSameElementsAs(
- LocalString.ReadAllFrom(@"
- a=us-a
- b=us-b
- c=us-c
- d=us-d
- f=us-f
- ")
- );
-
- source.Load(new CultureInfo("en-GB")).ShouldHaveTheSameElementsAs(new LocalString("a", "gb-A"));
-
- new XmlDocument().FromFile(
- "localization1".AppendPath(XmlDirectoryLocalizationStorage.MissingLocaleConfigFile))
- .DocumentElement.ChildNodes.Count.ShouldEqual(0);
-
-
- }
- }
-}
View
56 src/FubuLocalization.Tests/fill_in_keys_on_string_token.cs
@@ -1,56 +0,0 @@
-using NUnit.Framework;
-using FubuTestingSupport;
-
-namespace FubuLocalization.Tests
-{
- [TestFixture]
- public class fill_in_keys_on_string_token
- {
- [Test]
- public void all_keys_are_derived_from_the_field_name()
- {
- MyKeys.Key1.ToLocalizationKey().Key1.ShouldEqual("MyKeys:Key1");
-
- MyKeys.Key1.Key.ShouldEqual("Key1");
- MyKeys.Key2.Key.ShouldEqual("Key2");
- MyKeys.Key3.Key.ShouldEqual("Key3");
-
- MyKeys.Key1.DefaultValue.ShouldEqual("Default1");
- }
-
- [Test]
- public void all_keys_are_derived_from_the_field_name_2()
- {
- MyKeys2.Key1.ToLocalizationKey().Key1.ShouldEqual("MyKeys2:Key1");
-
- MyKeys2.Key1.Key.ShouldEqual("Key1");
- MyKeys2.Key2.Key.ShouldEqual("Key2");
- MyKeys2.Key3.Key.ShouldEqual("Key3");
-
- MyKeys2.Key1.DefaultValue.ShouldEqual("Default1");
- }
- }
-
- public class MyKeys : StringToken
- {
- public static readonly MyKeys Key1 = new MyKeys("Default1");
- public static readonly MyKeys Key2 = new MyKeys("Default2");
- public static readonly MyKeys Key3 = new MyKeys("Default3");
-
- public MyKeys(string defaultValue) : base(null, defaultValue, "MyKeys")
- {
- }
- }
-
- public class MyKeys2 : StringToken
- {
- public static readonly MyKeys2 Key1 = new MyKeys2("Default1");
- public static readonly MyKeys2 Key2 = new MyKeys2("Default2");
- public static readonly MyKeys2 Key3 = new MyKeys2("Default3");
-
- public MyKeys2(string defaultValue)
- : base(null, defaultValue, namespaceByType:true)
- {
- }
- }
-}
View
6 src/FubuLocalization.Tests/packages.config
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
- <package id="NUnit" version="2.5.10.11092" />
- <package id="RhinoMocks" version="3.6" />
- <package id="structuremap" version="2.6.3" />
-</packages>
View
76 src/FubuLocalization/Basic/AssemblyScanner.cs
@@ -1,76 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Reflection;
-using System.Linq;
-using FubuCore;
-
-namespace FubuLocalization.Basic
-{
- public interface ILocalizedProperties
- {
- IEnumerable<PropertyInfo> FindProperties();
- IEnumerable<StringToken> FindTokens();
- }
-
- public class AssemblyScanner
- {
- private readonly ILocalizationStorage _storage;
- private readonly CultureInfo _culture;
- private readonly Lazy<ILocalizationDataProvider> _provider;
-
- public AssemblyScanner(ILocalizationStorage storage, CultureInfo culture)
- {
- DefaultCulture = new CultureInfo("en-US");
-
- _storage = storage;
- _culture = culture;
-
- _provider = new Lazy<ILocalizationDataProvider>(() =>
- {
- var missingHandler = new LocalizationMissingHandler(_storage, DefaultCulture);
- var factory = new LocalizationProviderFactory(_storage, missingHandler,
- new LocalizationCache());
-
- return factory.BuildProvider(_culture);
- });
- }
-
- public CultureInfo DefaultCulture { get; set; }
-
- public void ScanAssembly(Assembly assembly)
- {
- assembly
- .GetExportedTypes()
- .Where(x => x.CanBeCastTo<StringToken>())
- .Each(ScanStringTokenType);
-
- assembly
- .GetExportedTypes()
- .Where(x => x.IsConcreteTypeOf<ILocalizedProperties>())
- .Each(type => ScanProperties(type.Create<ILocalizedProperties>()));
- }
-
- public void ScanStringTokenType(Type type)
- {
- type
- .GetFields(BindingFlags.Public | BindingFlags.Static)
- .Where(field => field.FieldType.CanBeCastTo<StringToken>())
- .Each(field =>
- {
- var token = field.GetValue(null).As<StringToken>();
- _provider.Value.GetTextForKey(token);
- });
-
- }
-
- public void ScanProperties(ILocalizedProperties properties)
- {
- properties.FindProperties().Each(prop => _provider.Value.GetHeader(prop));
-
- properties.FindTokens().Each(x => _provider.Value.GetTextForKey(x));
- }
-
-
- }
-}
View
13 src/FubuLocalization/Basic/ILocalizationCache.cs
@@ -1,13 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-
-namespace FubuLocalization.Basic
-{
- public interface ILocalizationCache
- {
- ILocaleCache CacheFor(CultureInfo culture, Func<IEnumerable<LocalString>> finder);
- void LoadCaches(Action<Action<CultureInfo, ILocaleCache>> loader);
- void Clear();
- }
-}
View
12 src/FubuLocalization/Basic/ILocalizationProviderFactory.cs
@@ -1,12 +0,0 @@
-using System;
-using System.Globalization;
-
-namespace FubuLocalization.Basic
-{
- public interface ILocalizationProviderFactory
- {
- void LoadAll(Action<string> tracer);
- ILocalizationDataProvider BuildProvider(CultureInfo culture);
- void ApplyToLocalizationManager();
- }
-}
View
17 src/FubuLocalization/Basic/ILocalizationStorage.cs
@@ -1,17 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-
-namespace FubuLocalization.Basic
-{
-
-
- public interface ILocalizationStorage
- {
- void WriteMissing(string key, string text, CultureInfo culture);
-
- void LoadAll(Action<string> tracer, Action<CultureInfo, IEnumerable<LocalString>> callback);
-
- IEnumerable<LocalString> Load(CultureInfo culture);
- }
-}
View
44 src/FubuLocalization/Basic/InMemoryLocalizationStorage.cs
@@ -1,44 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using FubuCore.Util;
-
-namespace FubuLocalization.Basic
-{
- public class InMemoryLocalizationStorage : ILocalizationStorage
- {
- private readonly Cache<CultureInfo, IList<LocalString>> _cache = new Cache<CultureInfo, IList<LocalString>>(x => new List<LocalString>());
- private readonly Cache<CultureInfo, IList<LocalString>> _missing = new Cache<CultureInfo, IList<LocalString>>(x => new List<LocalString>());
-
-
- public void Add(CultureInfo culture, string key, string text)
- {
- _cache[culture].Add(new LocalString(key, text));
- }
-
- public void Add(CultureInfo culture, string valuesText)
- {
- _cache[culture].AddRange(LocalString.ReadAllFrom(valuesText));
- }
-
- public void WriteMissing(string key, string text, CultureInfo culture)
- {
- _missing[culture].Add(new LocalString(key, text));
- }
-
- public void LoadAll(Action<string> tracer, Action<CultureInfo, IEnumerable<LocalString>> callback)
- {
- _cache.Each(callback);
- }
-
- public IEnumerable<LocalString> Load(CultureInfo culture)
- {
- return _cache[culture];
- }
-
- public IEnumerable<LocalString> RecordedMissingKeysFor(CultureInfo culture)
- {
- return _missing[culture];
- }
- }
-}
View
58 src/FubuLocalization/Basic/LocalizationCache.cs
@@ -1,58 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Threading;
-using FubuCore;
-
-namespace FubuLocalization.Basic
-{
- public class LocalizationCache : ILocalizationCache
- {
- private readonly Dictionary<string, ILocaleCache> _locales = new Dictionary<string, ILocaleCache>();
- private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
-
- public ILocaleCache CacheFor(CultureInfo culture, Func<IEnumerable<LocalString>> finder)
- {
- var cache = initialRead(culture);
- if (cache == null)
- {
- _lock.Write(() =>
- {
- if (!_locales.ContainsKey(culture.Name))
- {
- var data = finder();
- cache = new ThreadSafeLocaleCache(culture, data);
- _locales.Add(culture.Name, cache);
- }
- else
- {
- cache = _locales[culture.Name];
- }
- });
- }
-
- return cache;
- }
-
- public void LoadCaches(Action<Action<CultureInfo, ILocaleCache>> loader)
- {
- _lock.Write(() =>
- {
- _locales.Clear();
-
- loader((culture, cache) => _locales.Add(culture.Name, cache));
- });
- }
-
- private ILocaleCache initialRead(CultureInfo culture)
- {
- return _lock.Read(() => _locales.ContainsKey(culture.Name) ? _locales[culture.Name] : null);
- }
-
- public void Clear()
- {
- _lock.Write(() => _locales.Clear());
- }
-
- }
-}
View
57 src/FubuLocalization/Basic/LocalizationMissingHandler.cs
@@ -1,57 +0,0 @@
-using System;
-using System.Globalization;
-using System.Linq;
-using System.Text.RegularExpressions;
-using FubuCore;
-
-namespace FubuLocalization.Basic
-{
- public class LocalizationMissingHandler : ILocalizationMissingHandler
- {
- private readonly ILocalizationStorage _storage;
- private readonly CultureInfo _defaultCulture;
-
- public LocalizationMissingHandler(ILocalizationStorage storage, CultureInfo defaultCulture)
- {
- _storage = storage;
- _defaultCulture = defaultCulture;
- }
-
- public string FindMissingText(StringToken key, CultureInfo culture)
- {
- var defaultValue = culture.Name + "_" + key.Key;
- if (key.DefaultValue.IsNotEmpty() && culture.Equals(_defaultCulture))
- {
- defaultValue = key.DefaultValue;
- }
-
- _storage.WriteMissing(key.Key, defaultValue, culture);
-
- return defaultValue;
- }
-
- public string FindMissingProperty(PropertyToken property, CultureInfo culture)
- {
- var defaultValue = culture.Equals(_defaultCulture)
- ? property.Header ?? property.DefaultHeaderText(culture) ?? BreakUpCamelCase(property.PropertyName)
- : property.DefaultHeaderText(culture) ?? culture.Name + "_" + property.PropertyName;
-
- _storage.WriteMissing(property.StringTokenKey, defaultValue, culture);
-
- return defaultValue;
- }
-
- public static string BreakUpCamelCase(string fieldName)
- {
- var patterns = new[]
- {
- "([a-z])([A-Z])",
- "([0-9])([a-zA-Z])",
- "([a-zA-Z])([0-9])"
- };
- var output = patterns.Aggregate(fieldName,
- (current, pattern) => Regex.Replace(current, pattern, "$1 $2", RegexOptions.IgnorePatternWhitespace));
- return output.Replace('_', ' ');
- }
- }
-}
View
41 src/FubuLocalization/Basic/LocalizationProvider.cs
@@ -1,41 +0,0 @@
-using System.Globalization;
-using System.Reflection;
-
-namespace FubuLocalization.Basic
-{
- public class LocalizationProvider : ILocalizationDataProvider
- {
- private readonly ILocaleCache _localeCache;
- private readonly ILocalizationMissingHandler _missingHandler;
-
- public LocalizationProvider(ILocaleCache localeCache, ILocalizationMissingHandler missingHandler)
- {
- _localeCache = localeCache;
- _missingHandler = missingHandler;
- }
-
- public CultureInfo Culture
- {
- get { return _localeCache.Culture; }
- }
-
- public string GetTextForKey(StringToken key)
- {
- var localizationKey = key.ToLocalizationKey();
- return _localeCache
- .Retrieve(localizationKey, () => _missingHandler.FindMissingText(key, _localeCache.Culture));
- }
-
- public string GetHeader(PropertyInfo property)
- {
- return GetHeader(new PropertyToken(property));
- }
-
- public string GetHeader(PropertyToken property)
- {
- var localizationKey = new LocalizationKey(property.StringTokenKey);
- return _localeCache
- .Retrieve(localizationKey, () => _missingHandler.FindMissingProperty(property, _localeCache.Culture));
- }
- }
-}
View
51 src/FubuLocalization/Basic/LocalizationProviderFactory.cs
@@ -1,51 +0,0 @@
-using System;
-using System.Globalization;
-using System.Threading;
-using FubuCore.Util;
-
-namespace FubuLocalization.Basic
-{
- public class LocalizationProviderFactory : ILocalizationProviderFactory
- {
- private readonly ILocalizationStorage _storage;
- private readonly ILocalizationMissingHandler _missingHandler;
- private readonly ILocalizationCache _cache;
- private readonly Cache<CultureInfo, ILocalizationDataProvider> _providers;
-
-
- public LocalizationProviderFactory(ILocalizationStorage storage, ILocalizationMissingHandler missingHandler, ILocalizationCache cache)
- {
- _storage = storage;
- _missingHandler = missingHandler;
- _cache = cache;
-
- _providers = new Cache<CultureInfo, ILocalizationDataProvider>(culture => BuildProvider(culture));
- }
-
- public void LoadAll(Action<string> tracer)
- {
- _cache.LoadCaches(loader =>
- {
- _storage.LoadAll(tracer, (c, keys) =>
- {
- loader(c, new ThreadSafeLocaleCache(c, keys));
- });
- });
- }
-
- public ILocalizationDataProvider BuildProvider(CultureInfo culture)
- {
- return new LocalizationProvider(_cache.CacheFor(culture, () => _storage.Load(culture)), _missingHandler);
- }
-
- public ILocalizationDataProvider SelectProviderByThread()
- {
- return _providers[Thread.CurrentThread.CurrentUICulture];
- }
-
- public void ApplyToLocalizationManager()
- {
- LocalizationManager.RegisterProvider(SelectProviderByThread);
- }
- }
-}
View
210 src/FubuLocalization/Basic/XmlDirectoryLocalizationStorage.cs
@@ -1,210 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Xml;
-using FubuCore;
-using FubuCore.Configuration;
-using FubuCore.Util;
-
-namespace FubuLocalization.Basic
-{
- public class XmlDirectoryLocalizationStorage : ILocalizationStorage
- {
- public const string MissingLocaleConfigFile = "missing.locale.config";
- private const string Key = "key";
- private const string RootElement = "fubu-localization";
- private const string Missing = "missing";
- private static readonly string LeafElement;
- private readonly IEnumerable<string> _directories;
- private readonly IFileSystem _fileSystem = new FileSystem();
- private readonly string _missingLocaleFile;
- private readonly object _missingLocker = new object();
-
- static XmlDirectoryLocalizationStorage()
- {
- LeafElement = "string";
- }
-
- public XmlDirectoryLocalizationStorage(IEnumerable<string> directories)
- {
- _directories = directories;
-
- _missingLocaleFile = directories.First().AppendPath(MissingLocaleConfigFile);
- }
-
- public void WriteMissing(string key, string text, CultureInfo culture)
- {
- lock (_missingLocker)
- {
- var document = getMissingKeysDocument();
-
- var xpath = "{0}[@{1}='{2}']".ToFormat(Missing, Key, key);
- if (document.DocumentElement.SelectSingleNode(xpath) != null)
- {
- return;
- }
-
- document.DocumentElement.AddElement(Missing)
- .WithAtt(Key, key)
- .WithAtt("culture", culture.Name)
- .InnerText = text;
-
- document.Save(_missingLocaleFile);
- }
- }
-
- private XmlDocument getMissingKeysDocument()
- {
- return _missingLocaleFile.XmlFromFileWithRoot("missing-localization");
- }
-
- public void LoadAll(Action<string> tracer, Action<CultureInfo, IEnumerable<LocalString>> callback)
- {
- var fileSet = new FileSet{
- DeepSearch = false,
- Include = "*.locale.config",
- Exclude = "missing.locale.config"
- };
-
- var files = _directories
- .SelectMany(dir => _fileSystem.FindFiles(dir, fileSet))
- .Where(file => !Path.GetFileName(file).StartsWith("missing."));
-
- files
- .GroupBy(CultureFor)
- .Each(group =>
- {
- var strings = group.SelectMany(f =>
- {
- tracer("Reading localization data from " + f);
- return LoadFrom(f);
- });
- callback(group.Key, strings);
- });
- }
-
- public IEnumerable<LocalString> Load(CultureInfo culture)
- {
- // Just not going to worry about duplicates here
- var filename = GetFileName(culture);
- return _directories
- .Select(x => x.AppendPath(filename))
- .Where(file => _fileSystem.FileExists(file))
- .SelectMany(LoadFrom);
- }
-
- public bool HasMissingLocalizationKeys()
- {
- var document = getMissingKeysDocument();
- return document.DocumentElement.SelectNodes(Missing).Count > 0;
- }
-
-
- public static void Write(string directory, CultureInfo culture, IEnumerable<LocalString> strings)
- {
- var filename = GetFileName(culture);
- var file = directory.AppendPath(filename);
-
- Write(file, strings);
- }
-
- public static void Write(string file, IEnumerable<LocalString> strings)
- {
- var document = new XmlDocument();
- var root = document.WithRoot(RootElement);
-
- strings.OrderBy(x => x.value).Each(
- x => { root.AddElement(LeafElement).WithAtt(Key, x.value).InnerText = x.display; });
-
- document.Save(file);
- }
-
- public string MissingLocaleFile
- {
- get { return _missingLocaleFile; }
- }
-
- public void MergeAllMissing()
- {
-
- var cache = new Cache<string, IList<LocalString>> (key => new List<LocalString>());
- var document = getMissingKeysDocument();
- foreach (XmlElement element in document.DocumentElement.SelectNodes(Missing))
- {
- var culture = element.GetAttribute("culture");
- cache[culture].Add(toLocalString(element));
- }
-
- cache.Each(writeMissingKeys);
-
- var emptyMissing = new XmlDocument();
- emptyMissing.WithRoot(Missing);
- emptyMissing.Save(_missingLocaleFile);
- }
-
- private void writeMissingKeys(string culture, IEnumerable<LocalString> missingStrings)
- {
- var filename = GetFileName(culture);
- var file = _directories.First().AppendPath(filename);
-
- Console.WriteLine("Writing new to " + file);
-
- var existingStrings = LoadFrom(file);
- var newStrings = missingStrings.ToList();
- newStrings.RemoveAll(x => existingStrings.Any(s => s.value == x.value));
-
- // TODO -- come from behind and move this out into some kind of observer
- var length = newStrings.Max(x => x.value.Length) + 5;
- newStrings.Each(x =>
- {
- Console.WriteLine("{0} = {1}", x.value.PadLeft(length), x.display);
- });
-
- Console.WriteLine();
- Console.WriteLine();
-
- Write(file, existingStrings.Union(newStrings));
- }
-
-
- private static LocalString toLocalString(XmlElement element)
- {
- return new LocalString(element.GetAttribute(Key), element.InnerText);
- }
-
- public static IEnumerable<LocalString> LoadFrom(string file)
- {
- var document = file.XmlFromFileWithRoot(RootElement);
-
- foreach (XmlElement element in document.DocumentElement.SelectNodes(LeafElement))
- {
- yield return toLocalString(element);
- }
- }
-
- public static string GetFileName(CultureInfo culture)
- {
- var name = culture.Name;
- return GetFileName(name);
- }
-
- public static string GetFileName(string cultureName)
- {
- return "{0}.locale.config".ToFormat(cultureName);
- }
-
- public static CultureInfo CultureFor(string filename)
- {
- var cultureName = Path.GetFileName(filename).Split('.').First();
- return new CultureInfo(cultureName);
-
- }
-
- public IEnumerable<string> Directories
- {
- get { return _directories; }
- }
- }
-}
View
20 src/FubuLocalization/CurrentCultureContext.cs
@@ -1,20 +0,0 @@
-using System.Globalization;
-using System.Threading;
-
-namespace FubuLocalization
-{
- public class CurrentCultureContext : ICurrentCultureContext
- {
- public CultureInfo CurrentCulture
- {
- get { return Thread.CurrentThread.CurrentCulture; }
- set { Thread.CurrentThread.CurrentCulture = value; }
- }
-
- public CultureInfo CurrentUICulture
- {
- get { return Thread.CurrentThread.CurrentUICulture; }
- set { Thread.CurrentThread.CurrentUICulture = value; }
- }
- }
-}
View
83 src/FubuLocalization/FubuLocalization.csproj
@@ -1,83 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.30703</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{05E7BD1E-6AB0-4D6E-91EB-B004AFA1A619}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>FubuLocalization</RootNamespace>
- <AssemblyName>FubuLocalization</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Basic\AssemblyScanner.cs" />
- <Compile Include="Basic\ILocalizationCache.cs" />
- <Compile Include="Basic\ILocalizationProviderFactory.cs" />
- <Compile Include="Basic\InMemoryLocalizationStorage.cs" />
- <Compile Include="Basic\LocalizationCache.cs" />
- <Compile Include="Basic\LocalizationMissingHandler.cs" />
- <Compile Include="Basic\LocalizationProviderFactory.cs" />
- <Compile Include="CurrentCultureContext.cs" />
- <Compile Include="HeaderTextAttribute.cs" />
- <Compile Include="ICurrentCultureContext.cs" />
- <Compile Include="ILocaleCache.cs" />
- <Compile Include="ILocaleCacheContext.cs" />
- <Compile Include="ILocalizationDataProvider.cs" />
- <Compile Include="ILocalizationMissingHandler.cs" />
- <Compile Include="Basic\ILocalizationStorage.cs" />
- <Compile Include="LocalizationExtensions.cs" />
- <Compile Include="LocalizationKey.cs" />
- <Compile Include="LocalizationManager.cs" />
- <Compile Include="Basic\LocalizationProvider.cs" />
- <Compile Include="LocalString.cs" />
- <Compile Include="NulloLocalizationDataProvider.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="PropertyToken.cs" />
- <Compile Include="StringToken.cs" />
- <Compile Include="ThreadSafeLocaleCache.cs" />
- <Compile Include="Basic\XmlDirectoryLocalizationStorage.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\FubuCore\FubuCore.csproj">
- <Project>{342B987C-E0A4-4129-958D-8E08084E8A06}</Project>
- <Name>FubuCore</Name>
- </ProjectReference>
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
View
30 src/FubuLocalization/HeaderTextAttribute.cs
@@ -1,30 +0,0 @@
-using System;
-
-namespace FubuLocalization
-{
- [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
- public class HeaderTextAttribute : Attribute
- {
- public HeaderTextAttribute(string text)
- {
- Text = text;
- }
-
- private string _culture = "en-US";
-
- public string Culture
- {
- get
- {
- return _culture;
- }
- set
- {
- _culture = value;
- }
- }
-
- public string Text { get; private set; }
- public string DefaultText { get; set; }
- }
-}
View
10 src/FubuLocalization/ICurrentCultureContext.cs
@@ -1,10 +0,0 @@
-using System.Globalization;
-
-namespace FubuLocalization
-{
- public interface ICurrentCultureContext
- {
- CultureInfo CurrentCulture { get; set; }
- CultureInfo CurrentUICulture { get; set; }
- }
-}
View
12 src/FubuLocalization/ILocaleCache.cs
@@ -1,12 +0,0 @@
-using System;
-using System.Globalization;
-
-namespace FubuLocalization
-{
- public interface ILocaleCache
- {
- void Append(LocalizationKey key, string value);
- string Retrieve(LocalizationKey key, Func<string> missing);
- CultureInfo Culture { get; }
- }
-}
View
7 src/FubuLocalization/ILocaleCacheContext.cs
@@ -1,7 +0,0 @@
-namespace FubuLocalization
-{
- public interface ILocaleCacheContext
- {
- ILocaleCache Cache { get; }
- }
-}
View
13 src/FubuLocalization/ILocalizationDataProvider.cs
@@ -1,13 +0,0 @@
-using System.Globalization;
-using System.Reflection;
-
-namespace FubuLocalization
-{
- public interface ILocalizationDataProvider
- {
- CultureInfo Culture { get; }
- string GetTextForKey(StringToken key);
- string GetHeader(PropertyInfo property);
- string GetHeader(PropertyToken property);
- }
-}
View
10 src/FubuLocalization/ILocalizationMissingHandler.cs
@@ -1,10 +0,0 @@
-using System.Globalization;
-
-namespace FubuLocalization
-{
- public interface ILocalizationMissingHandler
- {
- string FindMissingText(StringToken key, CultureInfo culture);
- string FindMissingProperty(PropertyToken property, CultureInfo culture);
- }
-}
View
105