Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sören Deger 733 posts 2844 karma points c-trib
    Jan 07, 2015 @ 20:27
    Sören Deger
    0

    How use parameter with localizationService in Angularjs?

    Hi all,

    I have this line in a angularjs controller:

    notificationsService.success(localizationService.localize("mail2cms_settingsLoaded", $scope.mailbox.eMail));


    My key in en.xml looks like this:

    <key alias="settingsLoaded"><![CDATA[Settings for '%0%' are loaded!]]></key>


    The value of $scope.mailbox.eMail is a string like this: [email protected]

    But if I load my page with this custom property editor in a custom section I get only this notification:

    The parameter is truncate to 1 char. Have anyone an explanation for this?

    Or is the syntax for using a parameter in localizationService wrong? Unfortunately, I have not found this in the documentation on umbraco.github.io/belle/

     

    Best regards

    Sören

  • Sören Deger 733 posts 2844 karma points c-trib
    Jan 09, 2015 @ 06:27
    Sören Deger
    102

    I have a look into umbraco.services.js and I realized why it doesn't work.

    I need to pass an array as a parameter instead of strings.

    In my example above the code in angularjs controller must look like this:

    $scope.tokens = []; 
    $scope.tokens[0] = $scope.mailbox.eMail;
    notificationsService.success(localizationService.localize("mail2cms_settingsLoaded", $scope.tokens));

     

    I hope this helps anyone with similar problems.

     

    Best 

    Sören

  • Søren Erland Vestø 19 posts 42 karma points
    Jan 18, 2019 @ 12:19
    Søren Erland Vestø
    0

    A minor detail, but you don't actually need the "tokens" array. You can just do

    localizationService.localize('area_keytoparametizedvalue', ['valueofparameter0']);
    

    Other than that you spared me a headache :-)

  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Feb 21, 2015 @ 14:11
    Bjarne Fyrstenborg
    0

    Hi Sören

    Thanks for sharing this

    I had a similar case, where I needed to translate the messages in the notifications.
    But I didn't need to pass any arguments - just use the translation key from the respective language file in /Umbraco/Config/Lang/ 

    I managed to solve it like this:

    notificationsService.success(localizationService.localize("analytics_settingsSaved"));
    
    notificationsService.success(localizationService.localize("analytics_accountDetailsSaved"));
    
    notificationsService.success(localizationService.localize("analytics_profileDetailsSaved"));

    where the language file hae a format like this:

    <language alias="en" intName="English (UK)" localName="English (UK)" lcid="" culture="en-GB">
      ...
      <area alias="analytics">
        <key alias="settingsSaved">Settings have been saved</key>
        <key alias="accountDetailsSaved">Account details have been saved</key>
        <key alias="profileDetailsSaved">Profile details have been saved</key>
      </area>
    </language>


    /Bjarne 

  • Sören Deger 733 posts 2844 karma points c-trib
    Feb 23, 2015 @ 11:44
    Sören Deger
    0

    Hi Bjarne,

    thank you. Yes, this is the way without passing any arguments and will work if you have language entries without variables.


    Sören

Please Sign in or register to post replies

Write your reply to:

Draft