johnvisiomvp

Life with Visio and other Microsoft Toys!

Multilingual Toolkit does not work?

with one comment

After looking at my download stats last week, I decided to upgrade all my WP7 apps to WP8 and continue developing from the there. The stats should that it was no longer worth the effort of maintaining a WP7 version of the code. The existing programs would remain in the marketplace, but not be updated.

For most of my apps, the upgrade went fine, but one app seemed to have an issue with being multilingual. (If I was going to upgrade my apps, I might as well give the users a bit more than a WP8 version of what they had.) Unlike a new WP8 app, upgrading to multilingual was not an easy task. A Resource directory had to be added and several strategic pieces of code had to be added to handle the resource files. For some reason I had missed something in upgrading this one app. No matter what language you set the phone to, the app was in English.

So, I abandoned trying to tweak the app to get it to work and just created a new WP8 app. Turning on the Multilingual Toolkit, adding a few target languages was all that was needed to create a generic multilingual phone app. Then came the task of actually making the app useful.

  • All the files for the other pages of the original app and any extra files were copied to the directory of the new project.
  • All the extra references including the Phone Toolkit from were added.
  • The extra code from the original App.xaml and Mainpage.xaml were added to the project.
  • The records from the original AppResources.resx were copied to the new AppResources.resx
  • The project was compiled
  • The XLF files were selected and the translations were machine generated
  • One more compile

And it worked. Still not sure what exactly was wrong with the upgraded file, but I did notice that the new App.XAML did contain some resource handling code that was not in the upgraded version. Adding the missing code did not help, but it did indicate that there was something else missing.

So yes, I could have spent more time tracking down what was wrong, but it did show that starting with a clean program was a better choice. I would never know if there was something waiting to bite me.

In WP8, the process of adding multiple languages is simple

  • Install the Multilingual Toolkit
  • Turn it on
  • Populate AppResources with your phrases.
  • Find all the reference for Text= and Content=
  • Change the fixed text to use
    Text=”{Binding Path=LocalizedResources.thestring, Source={StaticResource LocalizedStrings}}” in the XAML and AppResources.thestring in the C# code
  • Compile
  • Select the languages
  • Select all the XLF files and generate a machine translation. You can improve the translations later.
  • Compile

You will now have a multilingual app.

Enjoy.

John…

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

March 19, 2014 at 12:52 pm

Visual Studio and the Multilingual Toolkit

leave a comment »

This August while taking a river cruise through Europe I created a multilingual phrase book. It worked great, but the way the multilingual toolkit worked with Visual Studio was a pain. Once you added words and phrases to the default language AppResource file, you had to launch the multilingual toolkit translation app to do the translation. Though it could be selected within Visual Studio, it ran as a standalone app and after performing the functions, the app had to be closed. This had to be repeated for each language you used. Any guesses hoe much fun doing 45 languages was?

It appears that the Visual Studio 2013 developers quietly brought the translation within Visual Studio, so now you just have to right click the xlf file and the translation is done without leaving Visual Studio. Far easier than launching many versions of the translation app and then closing them.

In Visual Studio, you have been able to select multiple files for a while, so… what if you right clicked on a bunch of xlf files? A new dialog opens with a progres bar for each XLF separated and a green check mark when done.

Like the XAML files with a C# file behind, the XLF files have a RESX file behind them. So you need those files to be hidden before you right click so that only the XLF files are selected.
XLF files
If you include a resx file in your selection you will not get the translation option. You can use the ctrl key to select the non contiguous XLF files like the sv.xlf file in this example.

As to the 45 language translations, I finally figured out that it was just a list of strings and I did not need to handle the information as a language file. That opened up the possibility of quite a few languages. All that was required was that the character set was supported on the Windows phone and I had a way of getting the strings translated. So, now it is a huge Excel spreadsheet with macros to go off and populate any new entries. When it is time to publish a new version, it is just a matter of copying a XML file to Visual Studio.

Sorry Bing, Google supports more languages.

It turns out that version 2.2 was released in Feb 2014.  There is more information here:

http://blogs.msdn.com/b/matdev/archive/2014/02/07/multilingual-app-toolkit-v2-2-released.aspx

 

Enjoy.

John…

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

March 16, 2014 at 2:01 pm

WP8 Looking for Mr SkyDrive

with one comment

So far, my phone apps have been self contained and did not talk with the real world.  So my latest app involves communicating with a PC. There are a number of articles on using web services, but I wanted to be out of the loop. The user should be able to transfer from their PC to the phone and back. The obvious path seemed to be to use the user’s SkyDrive. Create a SkyDrive file on a PC and it will show up on your phone. Let your app create a SkyDrive file on your phone and it will show up on your PC.

So what is the big deal about transferring files? If you can do it, it opens a large possible number of potential apps. By transferring files to the phone, you can preload files or you can collect data on the phone and then upload the results for further processing.

So how do you do it?

One of the first things that comes up on StackOverflow is an answer that there is no API for the SkyDrive. Which was true at the time it was written. Now that has changed, but there is a mixture of incomplete information out there. StackOverflow is a good resource, but it is loaded with a lot of misinformation and partial information. You can find things, but it is a lot of work.

Microsoft does have information, but it is mish mash of C#, Java and C++ for Windows RT, Windows apps and Window Phone. The user is left to dissect the information and try to piece something together. The one phone example compiles with more errors than lines of code. I know the guys at Microsoft are smart, BUT… How about showing how smart you are by making simple examples rather than creating convoluted examples. (I got lost with the Win 8 apps examples because they had everything including the kitchen sink). Creating simple examples requires a lot of talent.

There is also the issue of signing in to SkyDrive. It would be nice just to treat SkyDrive as another drive, but the phone is not mine, it belongs to the user. So it is just common courtesy for me to ask the owners permission before playing with their SkyDrive. So far the examples I have seen need some User Experience improvements. They provide a Sign In button, but allow the user to press another button that will then do nothing but complain that the Sign In button was not pressed. The proper experience should be not to provide a Sign In button, but allow the user to choose the function they want and then pop up a sign in dialog if it is required.

So, what have I learned?

  • Files placed on SkyDrive have a name, but from an phone app, you need to know the files file id. So you have to write your own file picker.
  • To work on the file you need to move it to isolated storage. This may mean cleaning up the SkyDrive file.
  • http://msdn.microsoft.com/en-us/library/live/hh826531.aspx is a good reference, but…
    • it is a mish mash of platforms and languages,
    • it contains mistakes for the phone…
      • Windows is not a valid branding
      • Windows.UI.Xaml and Windows.UI.Xaml.Controls are not valid references
      • There is no explanation of folder ids or file ids – they just appear
  • The Live SDK has evolved so you have to know what is different in each version.
  • Not all versions of the Live SDK support Windows Phone 8
  • ASync has been added to the mix
  • When creating files, they are placed at the root. Since others can use a user’s SkyDrive. More care is needed when placing the files. In Isolated Storage, the app has full control of files so does not have to be too concerned about file directories. On the SkyDrive, the developer has to be sure to play nice with others.

So, what would I like? A simple Windows Phone example of downloading a file from SkyDrive and uploading a file back. Of course, this will requiring some explanations of SkyDrive directories, file types and aSync. The example also needs to be complete. I have seen numerous posts on StackOverflow embellishing on an answer because something was missing. A variable needed to be defined or a using was missing. Visual Studio is good at resolving missing Usings, but not always.

Now to see if I can mould the bits and pieces I have found into a simple working app.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

February 6, 2014 at 2:57 am

WP7 Multilingual AppBar.

with one comment

The current phone app I am working on is based around a pivot and to get the most out of the pivot I want to use a different appbar for each pivot item. Luckily, Microsoft has a good article on how to do it.

How to use different app bars in a single Pivot control for Windows Phone

Unfortunately, the article has a few problems. The main ones deal with a need to know. This is a pivot and this article suggests placing the appbar in App.xaml. This is a pivot and only the page with the pivot needs to know about it or cares. This also means the background code will be in App.xaml.cs which complicates things. Since most of my apps have been multilingual, the solution did not handle the binding required for the resource file.

So the solution was to take the idea and move it to the page that had the pivot. This meant changing the xaml code from using Application.Resource to phone:PhoneApplicationPage.Resources and use throwaway values for the text. The SelectionChanged method of the pivot would take care of adding the correct text. Since I like to have optional menu items and there is no way to hide menu items, I left that up to the code behind and removed any references to the appbar menu from the xaml code. The resulting SelectionChanged method looked like.

private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
switch (((Pivot)sender).SelectedIndex)
{
case 1:
ApplicationBar = ((ApplicationBar)Resources["AppBar1"]);
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Text = AppResources.AppBar1a;
((ApplicationBarIconButton)ApplicationBar.Buttons[1]).Text = AppResources.AppBar1b;
((ApplicationBarIconButton)ApplicationBar.Buttons[2]).Text = AppResources.AppBar1c;
((ApplicationBarIconButton)ApplicationBar.Buttons[3]).Text = AppResources.AppBar1d;
break;
case 2:
ApplicationBar = ((ApplicationBar)Resources["AppBar2"]);
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Text = AppResources.AppBar2a;
((ApplicationBarIconButton)ApplicationBar.Buttons[1]).Text = AppResources.AppBar2b;
((ApplicationBarIconButton)ApplicationBar.Buttons[2]).Text = AppResources.AppBar2c;
break;
default:
ApplicationBar = ((ApplicationBar)Resources["AppBar0"]);
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Text = AppResources.AppBar0a;
((ApplicationBarIconButton)ApplicationBar.Buttons[1]).Text = AppResources.AppBar0b;
break;
}
ApplicationBar.MenuItems.Clear();
ApplicationBar.IsMenuEnabled = true;

ApplicationBarMenuItem appBarMenuItem;
appBarMenuItem = new ApplicationBarMenuItem(AppResources.lblLive);
appBarMenuItem.Click += new EventHandler(Click_Live);
ApplicationBar.MenuItems.Add(appBarMenuItem);
if (App.isTrial)
{
appBarMenuItem = new ApplicationBarMenuItem(AppResources.lblBuyNow);
appBarMenuItem.Click += new EventHandler(Click_Buy);
ApplicationBar.MenuItems.Add(appBarMenuItem);
}
if (App.EdomDog)
{
appBarMenuItem = new ApplicationBarMenuItem(AppResources.lblEdomDog);
appBarMenuItem.Click += new EventHandler(Click_EdomDog);
ApplicationBar.MenuItems.Add(appBarMenuItem);
}
}

Now, as the app evolves, I have an easy framework to build the appbars on. The code is contained to the page that needs it, it supports multiple languages and it supports optional items.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

January 15, 2014 at 9:42 am

MVA is not just for IT guys

with 2 comments

For the past month I have been looking at MVA – Microsoft Virtual Academy.  I did check it out when it was first released, but it basically had IT Pro related courses. Though I prefer to wear a dev hat, I did play an IT Pro in the past.

My IT Pro experiences were back in the days of the dinosaurs when I roamed mainframes in the basement of a large shopping center. So I am always curious how the industry has progressed. In those days, remote access involved using the phone to get the status from an operator and deciding if the system had to be rebooted. If it dead need rebooting, you had more than enough time to drive in before the system was ready. System testing was done at 2AM Sunday, provided IBM left you a large enough time window. Sometimes you felt you were on a NASCAR pit crew when you tried to see haw fast you could bring down a production system, bring up the test system, run the test(s), bring down the test system, bring up production and then verify it was ready for hand over from the dev team to the prod team. The game has changed, things are far easier, but there are far more interesting things to do and play with.

If you are just curious about a technology, check out one of their courses. It will not give you instant understanding, but it may give you some insight to be comfortable enough to go further.

The beauty of the courses is that they have a rewind button. Each student learns at their own pace and sometimes the instructor comes out with a gem that the student wants to hear again to make sure they understand – press rewind. (On the PowerShell course it was interesting to hear the verb Claused being used with reverence.) So, you took the course last month and aced it. Review the course and see if their are any gems you missed the first time around.

You scanned the PDFs that came with the course, slept through the video, but what sunk in? Most modules in the course come with Self tests that make you think. Can you make the 80% mark and get 100% completion on the course?

So why would a dev be interested in IT courses? Some of the tools used by IT Pros are useful to devs. I spent the weekend enjoying two courses on PowerShell – Getting Started with PowerShell and Advanced PowerShell and now I have a whole slew of questions to ask Clippy. They even have courses on Database Fundamentals, Big Data, Networking Fundaments and more

Over the past month, I got carried away checking out the various courses and made it to #1 in the Top Students in Canada for the week. I have slipped to #3, but I am now #2 in Canada for the month. So join me on the Top Student board and enjoy the learning experience.

Here are some developer related courses:
Fundamentals
C# Fundamentals: Development for Absolute Beginners
Programming in C# Jump Start
Windows 8
Windows 8 UX Design Jump Start
Essentials of Developing Windows Store Apps using C# Jump Start
Advanced Windows Store App Development using C# Jump Start
XAML Deep Dive for Windows & Windows Phone Apps Jump Start
Developing Windows Store Apps with HTML5 Jump Start
Windows Store Apps with HTML5 Refresh Jump Start
Advanced Windows Store App Development with HTML5 Jump Start
Building Windows Store Apps for iOS Developers Jump Start
Gaming Engines for Windows 8 Jump Start
Windows Phone
Windows Phone 8 Development for Absolute Beginners
Building Apps for Windows Phone 8 Jump Start
Build Apps for Both Windows 8 and Windows Phone 8 Jump Start
Visual Studio/ALM Applying ALM with Visual Studio 2012 Jump Start
Administering Visual Studio TFS 2012 Jump Start
Software Testing with Visual Studio 2012 Jump Start
Web
Developing ASP.NET MVC4 Web Applications Jump Start
HTML5 & CSS3 Fundamentals: Development for Absolute Beginners
Developing in HTML5 with JavaScript and CSS3 Jump Start
Building Web Apps with ASP.NET Jump Start
SharePoint
Developing Microsoft SharePoint® Server 2013 Core Solutions Jump Start
Lightswitch
Building Business Apps with Visual Studio Lightswitch

So check out MVA – Microsoft Virtual Academy

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

November 25, 2013 at 3:06 pm

WP Developer in a Guilded Cage.

with one comment

I have been working on Windows Phone apps for several years and I am still having trouble getting traction on creating new apps. Creating a Hello World is not a problem, but creating something more sophisticated requires a lot of effort. There is information out there, but it does take some work sifting through the chaff. There needs to be a way for the novices to get apprenticed. Currently, there are experts out there, but they are few compared to the number of developers. There are also novice experts who no more than a total novice, they may even no more than the experts on a specific topic.

It has been pointed out that certification is probably not the best way to find an expert. Certification only indicates that they can pass a test. For those with good memories, there are brain dumps available to help you pass. I have also sat on the other side of the fence and helped create certification tests, from criteria determination to actual question creation and evaluation. The questions are aimed at general knowledge rather than obscure information.

So most people, with a bit or work, should be able to pass. What has been suggested is that an apprentice system should be set up to help IT Pros/developers hone their craft. I would like to see a guild system where juniors learn from more senior professionals and in turn help others. Currently in the Windows Phone world it is two levels, the real experts and the others.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

October 13, 2013 at 3:36 am

Formatting Debug Writeline

with one comment

For the past few months, I have been working on a Windows Phone app that uses several tables. Most of the time when I debug, I rely heavily on Debug.Writeline to help me keep track of what is going on as I test an app.  If the app crashes, I can look at Output and get a better idea where the fail occurred than trying to wander back through the Visual Studio trace. In addition to the routine names I place in the Writeline statements, I include key values, so that I can read the history of the app before the crash. The only problem is that though I use Debug.Writeline(“[Teststring]Code={0} Name={1}”,LangCode, LangName); the code is free format and it gets hard to read a table when you encase a line like that in a foreach if the length of an element like LangCode can vary between two to five characters.

Luckily there is an easy way to format items within Debug.Writeline without using Format. I can replace {0} in the Debug.Writeline with {0,-5}. The “5″ sets the length of the output as five characters for the first item and the second items all line up. The minus sign indicates that the string is left justified. There are other formatting codes for numbers and dates. You can find more information on MSDN about Composite Formatting at http://msdn.microsoft.com/en-us/library/txafckwd.aspx It does not explicitly mention Debug.Writeline, but the information does apply. So if you need to print tables using Debug.Writeline to help with your debugging, try it out and check out what can be done with numerics and dates.

Though this information is out there, it is not easy to find. Luckily when I found this technique several years ago, I made a reference in OneNote. OneNote is an excellent tool for organizing trivia and I was able to quickly refind the link.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

October 12, 2013 at 10:31 am

Follow

Get every new post delivered to your Inbox.

Join 313 other followers