locked
MS Lightswitch Application - How to change application language RRS feed

  • Question

  • I am using MS Lightswitch application with Silverlight client. I have to change the application to arabic interface, and I tried by change Culture in projects General Properties tab, and then loop through all the fields/properties in the screen and changed it display name as below:

    iContentItem.DisplayName = "Something New Label In Arabic";

    Where iContentItem is Microsoft.LightSwitch.Presentation.IContentItem. Here is the screen I have changed some labels.

    MS Lightswitch screen change language

    Note that in details table, field's labels are changed to Arabic, also in the top buttons bar, labels are changed. But in the left side menu doesn't affected, it is showing english labels, and also Grid's column headings are also in english. Can anybody suggest how to convert these labels to arabic.


    Muhammad Idrees

    Thursday, December 3, 2015 12:40 PM

Answers

  • Hello

    I don't know about changing the language as such, but I do change column headings at run time and you could use a similar technique to sort out your column headings.

    In the _Created() event of the page in question I do the following:-

    partial void YourPageName_Created()
            {
                // Write your code here.
                this.FindControl("Your_Grid_Name").ControlAvailable += changeHeader;
            }

    Then you can have a function that does the hard work called......changeHeader.

            void changeHeader(object sender, ControlAvailableEventArgs e)
            {
                DataGrid subGrid;
                subGrid = e.Control as DataGrid;
    
                DataGridColumn col = (DataGridColumn)subGrid.Columns.Where(a => a.Header.ToString() == "TEXT_TO_MATCH").FirstOrDefault();
                if (col != null)
                {
                    ContentItemWrapperForColumnHeader headerFeature = (ContentItemWrapperForColumnHeader)col.Header;
                    headerFeature.ContentItem.DisplayName = "REPLACEMENT_TEXT_GOES_HERE!!";
                }
            }

    Of course, you will have to replace "YourPageName" with your page name, "Your_Grid_Name" with the name of your grid, "TEXT_TO_MATCH" with the column heading to change and "REPLACEMENT_TEXT_GOES_HERE" with whatever you want it to be! Remember that in the "REPLACEMENT_TEXT_GOES_HERE" you can use escape characters (i.e. \n will give you a line break which is good if your text is a bit long)

    Although this is only for the column headings you can see that in this Object Orientated world I am sure that there is a way through to update the other parts in exactly the same way.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Marked as answer by Angie Xu Thursday, December 24, 2015 11:33 AM
    Tuesday, December 8, 2015 11:33 AM

All replies

  • Can anybody suggest some solution, is it possible or not ?

    Muhammad Idrees

    Tuesday, December 8, 2015 7:34 AM
  • Hello

    I don't know about changing the language as such, but I do change column headings at run time and you could use a similar technique to sort out your column headings.

    In the _Created() event of the page in question I do the following:-

    partial void YourPageName_Created()
            {
                // Write your code here.
                this.FindControl("Your_Grid_Name").ControlAvailable += changeHeader;
            }

    Then you can have a function that does the hard work called......changeHeader.

            void changeHeader(object sender, ControlAvailableEventArgs e)
            {
                DataGrid subGrid;
                subGrid = e.Control as DataGrid;
    
                DataGridColumn col = (DataGridColumn)subGrid.Columns.Where(a => a.Header.ToString() == "TEXT_TO_MATCH").FirstOrDefault();
                if (col != null)
                {
                    ContentItemWrapperForColumnHeader headerFeature = (ContentItemWrapperForColumnHeader)col.Header;
                    headerFeature.ContentItem.DisplayName = "REPLACEMENT_TEXT_GOES_HERE!!";
                }
            }

    Of course, you will have to replace "YourPageName" with your page name, "Your_Grid_Name" with the name of your grid, "TEXT_TO_MATCH" with the column heading to change and "REPLACEMENT_TEXT_GOES_HERE" with whatever you want it to be! Remember that in the "REPLACEMENT_TEXT_GOES_HERE" you can use escape characters (i.e. \n will give you a line break which is good if your text is a bit long)

    Although this is only for the column headings you can see that in this Object Orientated world I am sure that there is a way through to update the other parts in exactly the same way.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Marked as answer by Angie Xu Thursday, December 24, 2015 11:33 AM
    Tuesday, December 8, 2015 11:33 AM
  • Thank you very much Otis, it works for grid headings.

    Do you have any idea how to change the menu items. Because grid is a control which we can access in screen as you suggested. But I don't know from which event/screen/file I have to change the navigation menu items text.

    I really appreciate if you can suggest me some direction.


    Muhammad Idrees

    Saturday, December 12, 2015 7:37 AM
  • Hello

    I am in the middle of a big project right now so cannot offer much help; however, there is a post here that allows you to show and hide the ribbon and toolbars that shows you how to access those particular objects. I am more than sure that you will be able to find something from here......and if not it'll give you a cool new "feature" that you can show people :)


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Tuesday, December 15, 2015 3:55 PM
  • As a holiday treat I had a quick look into this and it looks as if the navigation is very much read only. Below is a link to my test project that has LOTS of stuff in including the Helpers class that finds the navigation properties and shows the names but as they are read only can do nothing else

    https://onedrive.live.com/redir?resid=3AA76845FF98C175!1399&authkey=!AOOPoMSDEIZz26w&ithint=file%2czip

    Merry Christmas


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Thursday, December 24, 2015 12:16 PM
  • Thanks Otis.

    I am using VS 2012, and unable to run the demo you posted. Do you have any demo compatible with VS 2012. Sorry for taking your time, but I just caught with this issue.


    Muhammad Idrees

    Sunday, December 27, 2015 12:19 PM
  • Hello

    Sorry, I don't have VS 2012 so cannot do the update for you. As a helping hand I have posted the code to the helpers.cs page that is in the package. If you can create this page and then reference to it you can see what I am doing.......or not doing.

    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.LightSwitch.Threading;
    using Microsoft.LightSwitch.Runtime.Shell.Implementation.Standard;
    using Microsoft.LightSwitch.Presentation;
    using Microsoft.LightSwitch.Runtime.Shell.ViewModels.Implementation.Navigation;
    namespace LightSwitchApplication.UserCode
    {
        public class Helpers
        {
            /// <summary>
            /// My Attempt at trying to get to the Navigation Menu Items......
            /// Not going too well unfortunatly!!!!
            /// </summary>
            public static void MenuStuff()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    var con = MainMenu.Content as FrameworkElement;
    
                    var dcon = (NavigationViewModel)con.DataContext;
    
                    foreach (NavigationGroup navgrp in dcon.NavigationItems)
                    {
                        navgrp.DisplayName.ToString();                 //Group Name
                        foreach (var kid in navgrp.Children)
                        {
                            kid.DisplayName.ToString();             //Navigation within Group
                        }
                    }
                });
            }
    
            /// <summary>
            /// Hide the main menu altogether
            /// </summary>
            public static void HideMenu()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    MainMenu.Visibility = Visibility.Collapsed;
                });
            }
    
            /// <summary>
            /// Collapse the main menu
            /// </summary>
            public static void CollapseMenu()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    MainMenu.IsExpanded = false;
                });
            }
    
            /// <summary>
            /// Hide the RibbonBar altogether
            /// </summary>
            public static void HideRibbonBar()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    RibbonBar.Visibility = Visibility.Collapsed;
                });
            }
    
            /// <summary>
            /// Collapse the toolbar altogether
            /// </summary>
            public static void CollapseRibbonBar()
            {
                Dispatchers.Main.Invoke(() =>
                {
                    RibbonBar.IsCompressed = true;
                });
            }
    
            /// <summary>
            /// Get the Main Menu Control
            /// </summary>
            private static NavigationView MainMenu
            {
                get
                {
                    var root = System.Windows.Application.Current.RootVisual;
                    return (NavigationView)FindControlByName(root, "NavigationView");
                }
            }
    
            /// <summary>
            /// Get the Main RibbonBar Control
            /// </summary>
            private static RibbonCommandBar RibbonBar
            {
                get
                {
                    var root = System.Windows.Application.Current.RootVisual;
                    return (RibbonCommandBar)FindControlByName(root, "HomeTabItem");
                }
            }
    
            /// <summary>
            /// Find a control with the specified Name (recursively) - returns null if not found.
            /// </summary>
            public static DependencyObject FindControlByName(DependencyObject control, string name)
            {
                if (control == null)
                    return null;
    
                if (control.GetValue(FrameworkElement.NameProperty) != null && control.GetValue(FrameworkElement.NameProperty).ToString() == name)
                {
                    return control;
                }
    
                // When it is a ScrollViewer we need to use the .Content property
                if (control.GetType().Equals(typeof(ScrollViewer)))
                    control = ((ScrollViewer)control).Content as FrameworkElement;
    
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(control); i++)
                {
                    var child = FindControlByName(VisualTreeHelper.GetChild(control, i), name);
                    if (child != null)
                    {
                        return child;
                    }
                }
                return null;
            }
    
    
        }
    }

    There is a LOT of code there and 99.5% of it is commented or named well enough to see what is happening.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Tuesday, January 5, 2016 11:16 AM