Copied to clipboard

Flag this post as spam?

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


  • Jonathan Roberts 409 posts 1063 karma points
    Sep 22, 2015 @ 12:43
    Jonathan Roberts
    0

    Create Package Action to update Lang Files

    Hi, I have created a Package and my HTML file has a few Labels that I would like to use the Lang XML files to store the Text. How do I create a C# class which runs on Install so the users Lang.xml files are up to date? I have looked at https://our.umbraco.org/forum/umbraco-7/developing-umbraco-7-packages/46770-Creating-new-Sections-Can-we-auto-generate-dictionary-item but it doesnt say where I should create this code and how I can Implement my new label text. Thanks Jon

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Sep 22, 2015 @ 13:34
    Kevin Jump
    100

    Hi,

    If you create a class that inherits IPackageAction, you can then call that from the actions section of your package.

    This is something I have done for the OpeningSoon package (https://github.com/KevinJump/OpeningSoon/blob/master/OpeningSoonInstaller/OpeningSoonPackageActions.cs)

    This package action class calls a translation helper, which is heavily lifted from I lifted it from Articulate and Marchello but merges lang.xml files (https://github.com/KevinJump/OpeningSoon/blob/master/OpeningSoonInstaller/TranslationHelper.cs)

    once you have something you can just add it to the actions section of the package (either in umbraco or the package.xml file)

    <Action runat="install" undo="true" alias="OpeningSoon_AddLocalizationStuff" />
    
  • Jonathan Roberts 409 posts 1063 karma points
    Sep 22, 2015 @ 13:40
    Jonathan Roberts
    0

    Hi, Thanks for this.

    I had another investigate and found something like this to add in the Actions section of the Create a Package:

    <Action runat="install" 
    

    undo="true " alias="AddLanguageFileKey" language="en " position="end" area="template" key="demo" value="This is a demo string" />

    Would this work if all I had were a few updates?

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Sep 22, 2015 @ 13:56
    Kevin Jump
    1

    yeah that might work,

    the AddLanguageFileKey is actually a contrib package action (from http://packageactioncontrib.codeplex.com) I am not sure of the status of that in Umbraco 7, but the language file format hasn't changed in a while, so if it runs it should add the values for you.

    from Umbraco 7.3 the language files can live in the property type folder - so the code in the posts above merges that file if it's pre v7.3 - only real advantage is that you don't have to fiddle with the package.xml every time you change a language thing.

  • Jonathan Roberts 409 posts 1063 karma points
    Sep 22, 2015 @ 14:33
    Jonathan Roberts
    0

    Hi, No my idea didnt work - it didnt update the Lang files :(. When you mention create a Class in your above comment where would I create that class - in a seperate project dll? and then include that dll in my Package?

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Sep 22, 2015 @ 14:38
    Kevin Jump
    1

    Yes i would build the class into a dll and include it in the package. as long as it impliments IPacakgeAction you should be able to call it, that's how the OpeningSoon package does it.

  • Jonathan Roberts 409 posts 1063 karma points
    Sep 22, 2015 @ 15:48
    Jonathan Roberts
    0

    Amazing help - many thanks - I followed your instructions and looked at what you did in Opening Soon and it was as easy as you say - Create a new project to create your DLL and then call it in the Package.xml file. Make sure you have your Lang folder in the Plugin folder with your new language keys and Bob's your uncle :) Thanks again, Jon

Please Sign in or register to post replies

Write your reply to:

Draft