diff --git a/src/Umbraco.ModelsBuilder/Building/PropertyModel.cs b/src/Umbraco.ModelsBuilder/Building/PropertyModel.cs
index 1595b3f8..cf23a431 100644
--- a/src/Umbraco.ModelsBuilder/Building/PropertyModel.cs
+++ b/src/Umbraco.ModelsBuilder/Building/PropertyModel.cs
@@ -46,6 +46,11 @@ public class PropertyModel
///
public bool IsIgnored;
+ ///
+ /// Gets a value indicating whether this property allows varying by Culture.
+ ///
+ public bool IsCultureVariant;
+
///
/// Gets the generation errors for the property.
///
diff --git a/src/Umbraco.ModelsBuilder/Building/TextBuilder.cs b/src/Umbraco.ModelsBuilder/Building/TextBuilder.cs
index 8318c996..6b1b06d0 100644
--- a/src/Umbraco.ModelsBuilder/Building/TextBuilder.cs
+++ b/src/Umbraco.ModelsBuilder/Building/TextBuilder.cs
@@ -344,8 +344,16 @@ private void WriteProperty(StringBuilder sb, TypeModel type, PropertyModel prope
WriteClrType(sb, property.ClrTypeName);
sb.Append(">");
}
- sb.AppendFormat("(\"{0}\");\n",
- property.Alias);
+ if (property.IsCultureVariant && Config.RenderLanguageFallback)
+ {
+ sb.AppendFormat("(\"{0}\", fallback: Fallback.ToLanguage);\n",
+ property.Alias);
+ }
+ else
+ {
+ sb.AppendFormat("(\"{0}\");\n",
+ property.Alias);
+ }
}
if (property.Errors != null)
@@ -377,8 +385,16 @@ private void WriteProperty(StringBuilder sb, TypeModel type, PropertyModel prope
WriteClrType(sb, property.ClrTypeName);
sb.Append(">");
}
- sb.AppendFormat("(\"{0}\");\n",
- property.Alias);
+ if (property.IsCultureVariant && Config.RenderLanguageFallback)
+ {
+ sb.AppendFormat("(\"{0}\", fallback: Fallback.ToLanguage);\n",
+ property.Alias);
+ }
+ else
+ {
+ sb.AppendFormat("(\"{0}\");\n",
+ property.Alias);
+ }
}
private static IEnumerable SplitError(string error)
diff --git a/src/Umbraco.ModelsBuilder/Configuration/Config.cs b/src/Umbraco.ModelsBuilder/Configuration/Config.cs
index 4eb6a430..a097970c 100644
--- a/src/Umbraco.ModelsBuilder/Configuration/Config.cs
+++ b/src/Umbraco.ModelsBuilder/Configuration/Config.cs
@@ -76,6 +76,7 @@ public Config()
// default: false
EnableApi = ConfigurationManager.AppSettings[prefix + "EnableApi"].InvariantEquals("true");
+ RenderLanguageFallback = ConfigurationManager.AppSettings[prefix + "RenderLanguageFallback"].InvariantEquals("true");
AcceptUnsafeModelsDirectory = ConfigurationManager.AppSettings[prefix + "AcceptUnsafeModelsDirectory"].InvariantEquals("true");
// default: true
@@ -163,6 +164,7 @@ public Config(
bool enable = false,
ModelsMode modelsMode = ModelsMode.Nothing,
bool enableApi = true,
+ bool renderLanguageFallback = false,
string modelsNamespace = null,
bool enableFactory = true,
LanguageVersion languageVersion = DefaultLanguageVersion,
@@ -178,6 +180,7 @@ public Config(
ModelsMode = modelsMode;
EnableApi = enableApi;
+ RenderLanguageFallback = renderLanguageFallback;
ModelsNamespace = string.IsNullOrWhiteSpace(modelsNamespace) ? DefaultModelsNamespace : modelsNamespace;
EnableFactory = enableFactory;
LanguageVersion = languageVersion;
@@ -250,6 +253,14 @@ internal static string GetModelsDirectory(string root, string config, bool accep
///
public bool EnableApi { get; }
+ ///
+ /// Gets a value indicating whether the generated code adds language fallback on variant properties.
+ ///
+ ///
+ /// Default value is false.
+ ///
+ public bool RenderLanguageFallback { get; }
+
///
/// Gets a value indicating whether the API is installed.
///
diff --git a/src/Umbraco.ModelsBuilder/Umbraco/UmbracoServices.cs b/src/Umbraco.ModelsBuilder/Umbraco/UmbracoServices.cs
index 3ef0632f..84e2f32b 100644
--- a/src/Umbraco.ModelsBuilder/Umbraco/UmbracoServices.cs
+++ b/src/Umbraco.ModelsBuilder/Umbraco/UmbracoServices.cs
@@ -154,7 +154,9 @@ private IList GetTypes(PublishedItemType itemType, IContentTypeCompos
ClrName = GetClrName(propertyType.Name, propertyType.Alias),
Name = propertyType.Name,
- Description = propertyType.Description
+ Description = propertyType.Description,
+
+ IsCultureVariant = propertyType.Variations == ContentVariation.Culture
};
var publishedPropertyType = publishedContentType.GetPropertyType(propertyType.Alias);