@@ -156,28 +156,28 @@ private void PrepareAvailableLanguageModel(
156156 AvailableLanguageModel model ,
157157 AvailableResourcesModel resources ,
158158 Dictionary < int , GenericAttribute > translatedPercentageAtLastImport ,
159- Dictionary < string , PluginDescriptor > allPlugins = null ,
160159 Language language = null ,
161160 LanguageDownloadState state = null )
162161 {
163162 GenericAttribute attribute = null ;
164- PluginDescriptor pluginDescriptor = null ;
165163
166164 model . Id = resources . Id ;
165+ model . PreviousSetId = resources . PreviousSetId ;
167166 model . IsInstalled = language != null ;
168167 model . Name = GetCultureDisplayName ( resources . Language . Culture ) ?? resources . Language . Name ;
169168 model . LanguageCulture = resources . Language . Culture ;
170169 model . UniqueSeoCode = resources . Language . TwoLetterIsoCode ;
171170 model . Rtl = resources . Language . Rtl ;
172171 model . Version = resources . Version ;
173172 model . Type = resources . Type ;
174- model . NumberOfResources = resources . Aggregation . NumberOfResources ;
175- model . NumberOfTranslatedResources = resources . Aggregation . NumberOfTouched ;
176- model . TranslatedPercentage = Math . Round ( resources . Aggregation . TouchedPercentage , 2 ) ;
173+ model . Published = resources . Published ;
174+ model . DisplayOrder = resources . DisplayOrder ;
175+ model . TranslatedCount = resources . TranslatedCount ;
176+ model . TranslatedPercentage = resources . TranslatedPercentage ;
177177 model . IsDownloadRunning = state != null && state . Id == resources . Id ;
178178 model . UpdatedOn = _dateTimeHelper . ConvertToUserTime ( resources . UpdatedOn , DateTimeKind . Utc ) ;
179179 model . UpdatedOnString = model . UpdatedOn . RelativeFormat ( false , "f" ) ;
180- model . FlagImageFileName = GetFlagFileName ( resources . Language . TwoLetterIsoCode ) ;
180+ model . FlagImageFileName = GetFlagFileName ( resources . Language . Culture ) ;
181181
182182 if ( language != null && translatedPercentageAtLastImport . TryGetValue ( language . Id , out attribute ) )
183183 {
@@ -188,24 +188,7 @@ private void PrepareAvailableLanguageModel(
188188 model . TranslatedPercentageAtLastImport = percentAtLastImport ;
189189 }
190190 }
191-
192- // Installed plugin infos
193- if ( allPlugins != null )
194- {
195- foreach ( var systemName in resources . PluginSystemNames )
196- {
197- if ( allPlugins . TryGetValue ( systemName , out pluginDescriptor ) )
198- {
199- model . Plugins . Add ( new AvailableLanguageModel . PluginModel
200- {
201- SystemName = systemName ,
202- FriendlyName = pluginDescriptor . GetLocalizedValue ( _services . Localization , "FriendlyName" ) ,
203- IconUrl = _pluginMediator . GetIconUrl ( pluginDescriptor )
204- } ) ;
205- }
206- }
207- }
208- }
191+ }
209192
210193 private async Task < CheckAvailableResourcesResult > CheckAvailableResources ( bool enforce = false )
211194 {
@@ -298,28 +281,21 @@ private string GetCultureDisplayName(string culture)
298281 return null ;
299282 }
300283
301- private string GetFlagFileName ( string isoCode )
284+ private string GetFlagFileName ( string culture )
302285 {
303- isoCode = isoCode . EmptyNull ( ) . ToLower ( ) ;
286+ culture = culture . EmptyNull ( ) . ToLower ( ) ;
304287
305- if ( isoCode . HasValue ( ) )
288+ if ( culture . HasValue ( ) && culture . SplitToPair ( out string cultureLeft , out string cultureRight , "-" ) )
306289 {
307- switch ( isoCode )
308- {
309- case "en" :
310- isoCode = "us" ;
311- break ;
312- }
290+ var fileName = cultureRight + ".png" ;
313291
314- var fileName = isoCode + ".png" ;
315-
316- if ( System . IO . File . Exists ( CommonHelper . MapPath ( "~/Content/images/flags/" + fileName ) ) )
317- {
318- return fileName ;
319- }
320- }
292+ if ( System . IO . File . Exists ( CommonHelper . MapPath ( "~/Content/images/flags/" + fileName ) ) )
293+ {
294+ return fileName ;
295+ }
296+ }
321297
322- return null ;
298+ return null ;
323299 }
324300
325301 #endregion
@@ -350,26 +326,26 @@ public async Task<ActionResult> AvailableLanguages(bool enforce = false)
350326 var languages = _languageService . GetAllLanguages ( true ) ;
351327 var languageDic = languages . ToDictionarySafe ( x => x . LanguageCulture , StringComparer . OrdinalIgnoreCase ) ;
352328
353- var allPlugins = _pluginFinder . GetPluginDescriptors ( true ) ;
354- var allPluginsDic = allPlugins . ToDictionarySafe ( x => x . SystemName , StringComparer . OrdinalIgnoreCase ) ;
355-
356329 var downloadState = _asyncState . Get < LanguageDownloadState > ( ) ;
357330 var translatedPercentageAtLastImport = _genericAttributeService . GetAttributes ( "TranslatedPercentageAtLastImport" , "Language" ) . ToDictionarySafe ( x => x . EntityId ) ;
358331
359- var model = new List < AvailableLanguageModel > ( ) ;
360- var checkResult = await CheckAvailableResources ( enforce ) ;
332+ var checkResult = await CheckAvailableResources ( enforce ) ;
361333
362- foreach ( var resources in checkResult . Resources )
334+ var model = new AvailableLanguageListModel ( ) ;
335+ model . Languages = new List < AvailableLanguageModel > ( ) ;
336+ model . Version = checkResult . Version ;
337+ model . ResourceCount = checkResult . ResourceCount ;
338+
339+ foreach ( var resources in checkResult . Resources )
363340 {
364341 if ( resources . Language . Culture . HasValue ( ) )
365342 {
366- Language language = null ;
367- languageDic . TryGetValue ( resources . Language . Culture , out language ) ;
343+ languageDic . TryGetValue ( resources . Language . Culture , out Language language ) ;
368344
369- var alModel = new AvailableLanguageModel ( ) ;
370- PrepareAvailableLanguageModel ( alModel , resources , translatedPercentageAtLastImport , allPluginsDic , language , downloadState ) ;
345+ var alModel = new AvailableLanguageModel ( ) ;
346+ PrepareAvailableLanguageModel ( alModel , resources , translatedPercentageAtLastImport , language , downloadState ) ;
371347
372- model . Add ( alModel ) ;
348+ model . Languages . Add ( alModel ) ;
373349 }
374350 }
375351
@@ -437,20 +413,47 @@ public async Task<ActionResult> Edit(int id)
437413 // Provide combobox with downloadable resources for this language.
438414 var translatedPercentageAtLastImport = _genericAttributeService . GetAttributes ( "TranslatedPercentageAtLastImport" , "Language" ) . ToDictionarySafe ( x => x . EntityId ) ;
439415 var checkResult = await CheckAvailableResources ( ) ;
416+ string cultureParentName = null ;
440417
441- foreach ( var resources in checkResult . Resources )
442- {
443- var culture = resources . Language . Culture ;
444- if ( culture . HasValue ( ) && resources . Language . TwoLetterIsoCode . IsCaseInsensitiveEqual ( language . UniqueSeoCode ) )
445- {
446- var alModel = new AvailableLanguageModel ( ) ;
447- PrepareAvailableLanguageModel ( alModel , resources , translatedPercentageAtLastImport , null , language ) ;
418+ try
419+ {
420+ var ci = CultureInfo . GetCultureInfo ( language . LanguageCulture ) ;
421+ if ( ! ci . IsNeutralCulture && ci . Parent != null )
422+ {
423+ cultureParentName = ci . Parent . Name ;
424+ }
425+ }
426+ catch { }
448427
449- model . AvailableDownloadLanguages . Add ( alModel ) ;
450- }
451- }
428+ foreach ( var resources in checkResult . Resources . Where ( x => x . Published ) )
429+ {
430+ var srcCulture = resources . Language . Culture ;
431+ if ( srcCulture . HasValue ( ) )
432+ {
433+ var downloadDisplayOrder = srcCulture . IsCaseInsensitiveEqual ( language . LanguageCulture ) ? 1 : 0 ;
452434
453- return View ( model ) ;
435+ if ( downloadDisplayOrder == 0 && cultureParentName . IsCaseInsensitiveEqual ( srcCulture ) )
436+ {
437+ downloadDisplayOrder = 2 ;
438+ }
439+
440+ if ( downloadDisplayOrder == 0 && resources . Language . TwoLetterIsoCode . IsCaseInsensitiveEqual ( language . UniqueSeoCode ) )
441+ {
442+ downloadDisplayOrder = 3 ;
443+ }
444+
445+ if ( downloadDisplayOrder != 0 )
446+ {
447+ var alModel = new AvailableLanguageModel ( ) ;
448+ PrepareAvailableLanguageModel ( alModel , resources , translatedPercentageAtLastImport , language ) ;
449+ alModel . DisplayOrder = downloadDisplayOrder ;
450+
451+ model . AvailableDownloadLanguages . Add ( alModel ) ;
452+ }
453+ }
454+ }
455+
456+ return View ( model ) ;
454457 }
455458
456459 [ HttpPost , ParameterBasedOnFormName ( "save-continue" , "continueEditing" ) ]
@@ -739,7 +742,7 @@ public async Task<ActionResult> ImportXml(int id, FormCollection form, ImportMod
739742
740743 _services . Localization . ImportResourcesFromXml ( language , xmlDoc , null , false , mode , updateTouched ) ;
741744
742- _genericAttributeService . SaveAttribute ( language , "TranslatedPercentageAtLastImport" , availableResources . Aggregation . TouchedPercentage ) ;
745+ _genericAttributeService . SaveAttribute ( language , "TranslatedPercentageAtLastImport" , availableResources . TranslatedPercentage ) ;
743746
744747 NotifySuccess ( T ( "Admin.Configuration.Languages.Imported" ) ) ;
745748 }
@@ -801,7 +804,7 @@ private void DownloadCore(ILifetimeScope scope, CancellationToken ct, LanguageDo
801804 language . LanguageCulture = resources . Language . Culture ;
802805 language . UniqueSeoCode = resources . Language . TwoLetterIsoCode ;
803806 language . Name = GetCultureDisplayName ( resources . Language . Culture ) ?? resources . Name ;
804- language . FlagImageFileName = GetFlagFileName ( resources . Language . TwoLetterIsoCode ) ;
807+ language . FlagImageFileName = GetFlagFileName ( resources . Language . Culture ) ;
805808 language . Rtl = resources . Language . Rtl ;
806809 language . Published = false ;
807810 language . DisplayOrder = lastLanguage != null ? lastLanguage . DisplayOrder + 1 : 0 ;
@@ -815,7 +818,7 @@ private void DownloadCore(ILifetimeScope scope, CancellationToken ct, LanguageDo
815818
816819 services . Localization . ImportResourcesFromXml ( language , xmlDoc ) ;
817820
818- genericAttributeService . SaveAttribute ( language , "TranslatedPercentageAtLastImport" , resources . Aggregation . TouchedPercentage ) ;
821+ genericAttributeService . SaveAttribute ( language , "TranslatedPercentageAtLastImport" , resources . TranslatedPercentage ) ;
819822 }
820823 catch ( Exception exception )
821824 {
0 commit comments