@@ -74,66 +74,7 @@ internal PortalTemplateImporter(IPermissionDefinitionService permissionDefinitio
7474
7575 if ( ! string . IsNullOrEmpty ( templateToLoad . LanguageFilePath ) )
7676 {
77- XDocument languageDoc ;
78- using ( var reader = PortalTemplateIO . Instance . OpenTextReader ( templateToLoad . LanguageFilePath ) )
79- {
80- languageDoc = XDocument . Load ( reader ) ;
81- }
82-
83- // var localizedData = languageDoc.Descendants("data");
84- var localizedData = languageDoc . Descendants ( "data" )
85- . Where ( x => x . Attribute ( "name" ) != null )
86- . ToDictionary ( x => x . Attribute ( "name" ) . Value , x => x ) ;
87-
88- // check missed localize resource text
89- if ( templateToLoad . CultureCode != "en-US" )
90- {
91- // var rootDoc = languageDoc.Root;
92- var defLangFilePath = PortalTemplateIO . Instance . GetLanguageFilePath ( templateToLoad . TemplateFilePath , "en-US" ) ;
93- if ( ! string . IsNullOrEmpty ( defLangFilePath ) )
94- {
95- // var isModified = false;
96- XDocument defLanguageDoc ;
97- using ( var reader = PortalTemplateIO . Instance . OpenTextReader ( defLangFilePath ) )
98- {
99- defLanguageDoc = XDocument . Load ( reader ) ;
100- }
101-
102- var defData = defLanguageDoc . Descendants ( "data" ) ;
103- foreach ( var defNode in defData )
104- {
105- var key = defNode . Attribute ( "name" ) ? . Value ;
106- if ( string . IsNullOrEmpty ( key ) )
107- {
108- continue ;
109- }
110-
111- if ( ! localizedData . ContainsKey ( key ) )
112- {
113- // isModified = true;
114- // rootDoc.Add(new XElement(defNode));
115- localizedData . Add ( key , defNode ) ;
116- }
117- }
118-
119- }
120- }
121-
122- foreach ( var node in localizedData . Values )
123- {
124- var name = node . Attribute ( "name" ) ? . Value ;
125- if ( string . IsNullOrEmpty ( name ) )
126- {
127- continue ;
128- }
129-
130- var valueElement = node . Element ( "value" ) ;
131- if ( valueElement != null )
132- {
133- var value = valueElement . Value ;
134- buffer . Replace ( $ "[{ name } ]", value ) ;
135- }
136- }
77+ ReplaceTemplateTokens ( templateToLoad , buffer ) ;
13778 }
13879
13980 this . TemplatePath = Path . GetDirectoryName ( templateToLoad . TemplateFilePath ) ;
@@ -355,6 +296,71 @@ internal string CreateProfileDefinitions(int portalId)
355296 return strMessage ;
356297 }
357298
299+ private static void ReplaceTemplateTokens ( IPortalTemplateInfo templateToLoad , StringBuilder buffer )
300+ {
301+ XDocument languageDoc ;
302+ using ( var reader = PortalTemplateIO . Instance . OpenTextReader ( templateToLoad . LanguageFilePath ) )
303+ {
304+ languageDoc = XDocument . Load ( reader ) ;
305+ }
306+
307+ var localizedData = languageDoc . Descendants ( "data" )
308+ . Where ( x => x . Attribute ( "name" ) != null )
309+ . ToDictionary ( x => x . Attribute ( "name" ) . Value , x => x ) ;
310+
311+ // add default resource content that's missing in the translated resources
312+ if ( templateToLoad . CultureCode != "en-US" )
313+ {
314+ AddMissingDefaultResources ( templateToLoad , localizedData ) ;
315+ }
316+
317+ foreach ( var node in localizedData . Values )
318+ {
319+ var name = node . Attribute ( "name" ) ? . Value ;
320+ if ( string . IsNullOrEmpty ( name ) )
321+ {
322+ continue ;
323+ }
324+
325+ var valueElement = node . Element ( "value" ) ;
326+ if ( valueElement != null )
327+ {
328+ var value = valueElement . Value ;
329+ buffer . Replace ( $ "[{ name } ]", value ) ;
330+ }
331+ }
332+ }
333+
334+ private static void AddMissingDefaultResources ( IPortalTemplateInfo templateToLoad , Dictionary < string , XElement > localizedData )
335+ {
336+ var defaultLangFilePath = PortalTemplateIO . Instance . GetLanguageFilePath ( templateToLoad . TemplateFilePath , "en-US" ) ;
337+ if ( string . IsNullOrEmpty ( defaultLangFilePath ) )
338+ {
339+ return ;
340+ }
341+
342+ XDocument defaultLanguageDoc ;
343+ using ( var reader = PortalTemplateIO . Instance . OpenTextReader ( defaultLangFilePath ) )
344+ {
345+ defaultLanguageDoc = XDocument . Load ( reader ) ;
346+ }
347+
348+ var defaultData = defaultLanguageDoc . Descendants ( "data" ) ;
349+ foreach ( var defaultNode in defaultData )
350+ {
351+ var key = defaultNode . Attribute ( "name" ) ? . Value ;
352+ if ( string . IsNullOrEmpty ( key ) )
353+ {
354+ continue ;
355+ }
356+
357+ if ( ! localizedData . ContainsKey ( key ) )
358+ {
359+ localizedData . Add ( key , defaultNode ) ;
360+ }
361+ }
362+ }
363+
358364 private static void ParseExtensionUrlProviders ( XPathNavigator providersNavigator , int portalId )
359365 {
360366 var providers = ExtensionUrlProviderController . GetProviders ( portalId ) ;
@@ -1442,4 +1448,3 @@ private void AddFolderPermissions(int portalId, int folderId)
14421448 }
14431449 }
14441450}
1445-
0 commit comments