Skip to content

Commit

Permalink
Downgraded to 4.0 and removed some unneccessary stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen committed Jul 3, 2013
1 parent 6779bd8 commit 6e6f381
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 27 deletions.
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EPiServer.Libraries.Localization</RootNamespace>
<AssemblyName>EPiServer.Libraries.Localization</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -53,6 +54,10 @@
<HintPath>..\packages\EPiServer.CMS.Core.7.0.586.16\lib\net40\EPiServer.BaseLibrary.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="EPiServer.Configuration, Version=7.0.586.1, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EPiServer.CMS.Core.7.0.586.16\lib\net40\EPiServer.Configuration.dll</HintPath>
</Reference>
<Reference Include="EPiServer.Data, Version=7.0.859.16, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EPiServer.Framework.7.0.859.16\lib\net40\EPiServer.Data.dll</HintPath>
Expand All @@ -63,10 +68,12 @@
<HintPath>..\packages\EPiServer.Framework.7.0.859.16\lib\net40\EPiServer.Framework.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<Reference Include="EPiServer.Packaging">
<HintPath>..\References\EPiServer.Packaging.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\log4net.2.0.0\lib\net40-full\log4net.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\..\..\Web\EPiServer\CommunityPlayground\Web\bin\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
Expand Down
4 changes: 2 additions & 2 deletions EPiServer.Libraries.Localization/Models/TranslationItem.cs
Expand Up @@ -115,14 +115,14 @@ public ReadOnlyCollection<string> MissingValues
/// <summary>
/// Gets the translated values for this item.
/// </summary>
public ReadOnlyDictionary<string, string> TranslatedValues
public Dictionary<string, string> TranslatedValues
{
get
{
PageDataCollection allLanguages = DataFactory.Instance.GetLanguageBranches(this.PageLink);

return
new ReadOnlyDictionary<string, string>(
new Dictionary<string, string>(
allLanguages.ToDictionary(
language => new CultureInfo(language.LanguageID).NativeName,
language => ((TranslationItem)language).Translation));
Expand Down
Expand Up @@ -14,7 +14,6 @@
[assembly: AssemblyProduct("EPiServer.Libraries.Localization")]
[assembly: AssemblyCopyright("Copyright © Jeroen Stemerdink 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("en")]

[assembly: ComVisible(false)]
[assembly: CLSCompliant(false)]
Expand Down
74 changes: 58 additions & 16 deletions EPiServer.Libraries.Localization/TranslationFactory.cs
Expand Up @@ -55,16 +55,32 @@ public sealed class TranslationFactory

#endregion

#region Fields

/// <summary>
/// The available languages
/// </summary>
private IEnumerable<CultureInfo> availableLanguages;

/// <summary>
/// The content repository
/// </summary>
private IContentRepository contentRepository;

/// <summary>
/// The translation container reference
/// </summary>
private PageReference translationContainerReference;

#endregion

#region Constructors and Destructors

/// <summary>
/// Prevents a default instance of the <see cref="TranslationFactory" /> class from being created.
/// </summary>
private TranslationFactory()
{
this.ContentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
this.TranslationContainerReference = this.GetTranslationContainer();
this.AvailableLanguages = this.GetAvailableLanguages();
}

#endregion
Expand Down Expand Up @@ -95,19 +111,43 @@ public static TranslationFactory Instance
}

/// <summary>
/// Gets or sets the available languages.
/// Gets the available languages.
/// </summary>
public IEnumerable<CultureInfo> AvailableLanguages { get; set; }
public IEnumerable<CultureInfo> AvailableLanguages
{
get
{
return this.availableLanguages ?? (this.availableLanguages = this.GetAvailableLanguages());
}
}

/// <summary>
/// Gets or sets the content repository.
/// Gets the reference to the translation container.
/// </summary>
public IContentRepository ContentRepository { get; set; }
public PageReference TranslationContainerReference
{
get
{
return this.translationContainerReference
?? (this.translationContainerReference = this.GetTranslationContainer());
}
}

#endregion

#region Properties

/// <summary>
/// Gets or sets the reference to the translation container.
/// Gets the content repository.
/// </summary>
public PageReference TranslationContainerReference { get; set; }
private IContentRepository ContentRepository
{
get
{
return this.contentRepository
?? (this.contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>());
}
}

#endregion

Expand Down Expand Up @@ -191,8 +231,9 @@ private void AddCategoryElement(XmlWriter xmlWriter, ContentReference container,
foreach (TranslationItem translationItem in
children.Select(
contentReference =>
this.ContentRepository.Get<PageData>(
contentReference, new LanguageSelector(cultureInfo.Name))).OfType<TranslationItem>().Select(page => page))
this.ContentRepository.Get<PageData>(contentReference, new LanguageSelector(cultureInfo.Name)))
.OfType<TranslationItem>()
.Select(page => page))
{
xmlWriter.WriteStartElement("category");
xmlWriter.WriteAttributeString("name", translationItem.OriginalText);
Expand Down Expand Up @@ -263,12 +304,12 @@ private void AddElement(XmlWriter xw, ContentReference container, CultureInfo cu
/// </returns>
private IEnumerable<CultureInfo> GetAvailableLanguages()
{
IEnumerable<CultureInfo> availableLanguages =
IEnumerable<CultureInfo> languages =
this.ContentRepository.GetLanguageBranches<PageData>(this.TranslationContainerReference)
.Select(pageData => pageData.Language)
.ToList();

return availableLanguages;
return languages;
}

/// <summary>
Expand All @@ -279,16 +320,17 @@ private IEnumerable<CultureInfo> GetAvailableLanguages()
/// </returns>
private PageReference GetTranslationContainer()
{
PageReference containerPageReference =
this.ContentRepository.Get<ContentData>(ContentReference.StartPage)
PageReference containerPageReference = ContentReference.StartPage;

this.ContentRepository.Get<ContentData>(ContentReference.StartPage)
.GetPropertyValue("TranslationContainer", ContentReference.StartPage);

if (containerPageReference == ContentReference.StartPage)
{
Logger.Info("[Localization] No translation container specified.");

TranslationContainer containerReference =
this.ContentRepository.GetChildren<TranslationContainer>(containerPageReference).FirstOrDefault();
this.ContentRepository.GetChildren<PageData>(containerPageReference).OfType<TranslationContainer>().FirstOrDefault();

if (containerReference != null)
{
Expand Down
2 changes: 1 addition & 1 deletion EPiServer.Libraries.Localization/TranslationProvider.cs
Expand Up @@ -72,7 +72,7 @@ public override void Initialize(string name, NameValueCollection config)
/// <summary>
/// Load the translations.
/// </summary>
internal void LoadTranslations()
public void LoadTranslations()
{
try
{
Expand Down
6 changes: 3 additions & 3 deletions EPiServer.Libraries.Localization/packages.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EPiServer.CMS.Core" version="7.0.586.16" targetFramework="net40" />
<package id="EPiServer.Framework" version="7.0.859.16" targetFramework="net40" />
<package id="log4net" version="2.0.0" targetFramework="net40" />
<package id="EPiServer.CMS.Core" version="7.0.586.16" targetFramework="net45" />
<package id="EPiServer.Framework" version="7.0.859.16" targetFramework="net45" />
<package id="log4net" version="2.0.0" targetFramework="net45" />
</packages>

0 comments on commit 6e6f381

Please sign in to comment.