diff --git a/PxWeb/Code/Api2/DataSource/PxFile/PxFileBuilder2.cs b/PxWeb/Code/Api2/DataSource/PxFile/PxFileBuilder2.cs new file mode 100644 index 00000000..b12b8e65 --- /dev/null +++ b/PxWeb/Code/Api2/DataSource/PxFile/PxFileBuilder2.cs @@ -0,0 +1,68 @@ +using System.Globalization; + +using PCAxis.Paxiom; + +namespace PxWeb.Code.Api2.DataSource.PxFile +{ + internal class PxFileBuilder2 : PXFileBuilder + { + public override bool BuildForSelection() + { + var meta = base.Model.Meta; + var result = base.BuildForSelection(); + if (meta.ContentVariable is null) + { + // If there is no content variable, we create one. + + try + { + // The name of the content variable is localized based on the language of the metadata. + var name = PCAxis.Paxiom.Localization.PxResourceManager.GetResourceManager() + .GetString("ApiContentsVariableName", new CultureInfo(meta.Language)); + + // Create the content variable + var contentVariable = new Variable(name, "CONTENTS", PlacementType.Stub, meta.NumberOfLanguages); + contentVariable.IsContentVariable = true; + + // Create the value for the content variable from the meta contents + var value = new Value(meta.Contents, meta.NumberOfLanguages); + PaxiomUtil.SetCode(value, "content"); + // Move the contentInfo from tablelevel to the content value + value.ContentInfo = meta.ContentInfo; + meta.ContentInfo = null; + contentVariable.Values.Add(value); + + // Insert the content variable as the first variable in the stub + meta.Stub.Insert(0, contentVariable); + meta.Variables.Insert(0, contentVariable); + meta.ContentVariable = contentVariable; + + // Add text and ContentInfo for all languages + var languages = meta.GetAllLanguages(); + var currentLanguage = meta.CurrentLanguage; + for (int i = 0; i < languages.Length; i++) + { + var lang = languages[i]; + + meta.SetLanguage(i); + + // Add the label for each language + contentVariable.Name = PCAxis.Paxiom.Localization.PxResourceManager.GetResourceManager() + .GetString("ApiContentsVariableName", new CultureInfo(lang)); + + // Set the value text in diffrent languages + value.Value = meta.Contents; + } + meta.SetLanguage(currentLanguage); + } + catch (Exception) + { + result = false; + } + } + + return result; + + } + } +} diff --git a/PxWeb/Code/Api2/DataSource/PxFile/PxFileDataSource.cs b/PxWeb/Code/Api2/DataSource/PxFile/PxFileDataSource.cs index a086239a..52dae0c5 100644 --- a/PxWeb/Code/Api2/DataSource/PxFile/PxFileDataSource.cs +++ b/PxWeb/Code/Api2/DataSource/PxFile/PxFileDataSource.cs @@ -38,7 +38,7 @@ public PxFileDataSource(IPxFileConfigurationService pxFileConfigurationService, /// Builder object, null if builder could not be created public IPXModelBuilder? CreateBuilder(string id, string language) { - var builder = new PCAxis.Paxiom.PXFileBuilder(); + var builder = new PxFileBuilder2(); var path = _tablePathResolver.Resolve(language, id, out bool selectionExists); diff --git a/PxWeb/wwwroot/Languages/pxlang.no.xml b/PxWeb/wwwroot/Languages/pxlang.no.xml index 4080ba69..5787ffee 100644 --- a/PxWeb/wwwroot/Languages/pxlang.no.xml +++ b/PxWeb/wwwroot/Languages/pxlang.no.xml @@ -1,4 +1,4 @@ - + @@ -55,4 +55,5 @@ + diff --git a/PxWeb/wwwroot/Languages/pxlang.sv.xml b/PxWeb/wwwroot/Languages/pxlang.sv.xml index 8579618b..531c2195 100644 --- a/PxWeb/wwwroot/Languages/pxlang.sv.xml +++ b/PxWeb/wwwroot/Languages/pxlang.sv.xml @@ -1,4 +1,4 @@ - + @@ -51,4 +51,5 @@ - \ No newline at end of file + + diff --git a/PxWeb/wwwroot/Languages/pxlang.xml b/PxWeb/wwwroot/Languages/pxlang.xml index 95337f22..cfb83b9c 100644 --- a/PxWeb/wwwroot/Languages/pxlang.xml +++ b/PxWeb/wwwroot/Languages/pxlang.xml @@ -1,4 +1,4 @@ - + @@ -111,4 +111,5 @@ +