Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

GetAllStringsByCulture returns different result than GetStringByCulture with missing strings

Found in

EPiServer.CMS.Core 7.5.394.2

Fixed in

EPiServer.CMS.Core 10.1.0

(Or a related package)

Created

Sep 22, 2016

Updated

Nov 14, 2016

Area

CMS Core

State

Closed, Fixed and tested


Description

Steps to reproduce

1. Use a language file with this content:

<?xml version="1.0" encoding="utf-8"?>
<languages>
    <language name="français" id="fr">
        <test>
            <string1>French string 1</string1>
        </test>
    </language>
    <language name="English" id="en">
        <test>
            <string1>English string 1</string1>
            <string2>English string 2</string2>
        </test>
    </language>
</languages>

2. Set the localization element in Framework.config to have missing messages

<localization fallbackBehavior="MissingMessage, Echo" fallbackCulture="en">

3. Add the following code to a razor view (Example: /Views/Shared/Header.cshtml in alloy mvc templates)

@{
    var resourceItems = EPiServer.Framework.Localization.LocalizationService.Current.GetAllStringsByCulture("test", System.Globalization.CultureInfo.GetCultureInfo("fr"));
    foreach (var item in resourceItems)
    {
        @String.Format("GetAllStringsByCulture Results -> Key: {0} Value: {1}", item.Key, item.Value)
        <br />
        var getStringByCulture = EPiServer.Framework.Localization.LocalizationService.Current.GetStringByCulture(item.Key, System.Globalization.CultureInfo.GetCultureInfo("fr"));
        @String.Format("GetStringByCulture Results -> Key: {0} Value: {1}", item.Key, getStringByCulture);
        <br />
    }
}

Expected:
The output from GetAllStringByCulture produces the same result as GetStringByCulture.

Actual:
There's a difference on the string that has a translation in English but not French:

GetAllStringsByCulture Results -> Key: /test/string2 Value: [Missing text '/test/string2' for 'English']
GetStringByCulture Results -> Key: /test/string2 Value: [Missing text '/test/string2' for 'French']