johnvisiomvp

Life with Visio and other Microsoft Toys!

Archive for the ‘Windows Phone 7’ Category

Universal Apps – Multilingual Toolkit

leave a comment »

I fell in love with the Multilingual Toolkit when it was first introduced and found it very useful to add multiple languages to my apps. The only down side was that the submission process increased with each language. Even so, the Toolkit was useful in translating the text that is submitted with the app. All I had to do was add extra strings to the project, have them translations and then use the translations in the submission.

The XLF files use an industry standard for translators, so it is a very useful way to communicate with translators. The translator may have his own application for handling the XLF file, but the Toolkit does come with a useful app that anyone can use to do the translation. Unfortunately, the first release seemed to indicate that you had to install Visual Studio, the current version still seems to be a part of Visual Studio.

Of course, that familiarity caused problems. When you add languages in WP7 or WP8, the toolkit would automatically add the resource file (resx) and the XLF file for that language. With 8.1, only the XLF file is added. Of course, correcting that mistake is a mistake, only the resource file for the default language is needed. If you add the missing resource files, you will get a cryptic error message about duplication.

Rather than AppResources.resx, 8.1 uses resw files and the name is string/EN/Resources.resw. Converting from resx to resw is just a matter of renaming the extension, but I prefer to just copy all the strings and paste. I have yet to try it, but it should be possible to add the language to the filename as was done in WP7 / WP8.

With 8.1 the C# code for using strings from the resource file is to add

var loader = new Windows.ApplicationModel.Resources.ResourceLoader();

and
ErrorBlock.Text = loader.GetString(“ErrorCode01”)

In the xaml it is a matter of

x:Uid="Help"

to the textblock or button. This will overwrite the content of the Text or Content parameter, but they should be left in for editing. I tend to add an x to the end of the test. Unlike in WP7 and WP8, Visual Studio does not show the resource string in the editor. So the overwritten string are useful for determining the look and feel while editing.

Also  there is no XML that shows the languages being used, so the task of removing a language is just a matter of deleting the appropriate XLF file.

Another interesting thing is that the UIC can change several attributes. So for one use of a UIC, you can change the text and the width for a textblock. In the resource file it would be Help.Text and Help.Width.

Enjoy.

John Marshall… Visio MVP       Visio.MVPs.org

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

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

WP7 Thems Mighty Big Words Partner.

with one comment

During one of the local user groups presentations, I had to send several notes to the presenter and to some of the organizers.  At the time I wrote on a notepad (the old fashion type). Considering my terrible handwriting it was not a great success, so I decided to write a Windows Phone app for that. The idea was to write an app that would show a message in the largest possible font and since the message would probably be larger than the phone, I chose to make the message scroll. Through testing, it was found that even though it was a smaller font, it was easier to read the message in landscape than in portrait. The phone supports two landscape orientations so I used the inverted landscape to show a second message. Flip the phone and you can quickly display a second message. I found that I needed the first message to get the person’s attention, the right person.

The app has four screens, the main one is where the messages are managed, the display to show the message, a colour control window and the mandatory help page.

bnr001  bnr002Bnr003

The main page allows you to enter two messages and provides hints as you type. Below that is a button that display what colours will be used for the text and the background. Pressing it will take you to a page so you can select the colours. Below that is a list of messages you can select from or add to. When you enter a message into the primary message area, a plus sign appears next to the list indicating that the phrase is unique and can be added to the list. When you select a message from the list an arrow appears next to the primary and secondary message so you can quickly add the message from the list to the primary or secondary message. A trash can will also appear next to the list indicating that the message can be deleted.

The appbar contains four buttons. The first plays the message, the second will pin to the start screen, the third is the usual help page and the final one will swap the primary and secondary messages.

bnr004The select Colour page will allow you to change the background colour and the colour of the text. The first three sliders control the background colour and the last three the text colour. There is a button at the bottom to swap the background and text colours.

bnr005

When you chose to pin to the Start Screen, the tile will show the two messages and the center of the tile will show the background colour and text colour. The tiles will give you quick access to common messages or ones you want to set up in advance.

bnr006    Bnr008    Bnr009

The display will show the text in the largest possible font for the orientation, leaving room for descenders. The display has two app bar buttons. One will pause the scrolling, so the screen speed can be adjusted by a slider. The other button will swap the colours. Changing the orientation of the phone to inverted landscape will display the secondary message.

In the past, I have used the app to communicate the length of a train car, send messages to people on the platform and next month I will be using it as a greeting board when we try to meet our contact at the airport in Amsterdam. I would be interested in hearing other applications. Though I did get kicked under the table when I used it to ask the waiter for the bill.

This app is available in German, English, Spanish, French, Italian, Polish and Swedish. It is available as a paid app or a trial version. The trial version has ads, limits the length of the messages, the number of messages stored and the number of tiles created.

You can download the trial version at http://www.windowsphone.com/en-us/store/app/banner/696719a5-e1f7-4baa-b4c0-69108a8aae0e

If you like or do not like it, I would appreciate some constructive reviews. Though I have moved on to my next app, I still would like to hear how I can improve this app. I did think of selecting the colours by name, but with a multilingual app, a number of names do not translate properly.

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

July 24, 2013 at 2:26 am

WP7 Problem with Tiles – orphans

with 2 comments

I have a new WP app – Banner

http://visio.mvps.org/WP7Apps/default.html

or

http://www.windowsphone.com/en-us/store/app/banner/696719a5-e1f7-4baa-b4c0-69108a8aae0e

that displays a message in the largest possible font for a given orientation as a scrolling banner. Inverted landscape displays a secondary message.  To allow the user quick access to a message, the original design included secondary tiles, but other than text, the tiles were all the same boring image. Luckily Robert Fonseca-Ensor provided a colourful solution. http://code.msdn.microsoft.com/wpapps/Building-Dynamic-Live-52bdc195 . As a demo, it worked great but there were a few issues. The first was how to create the image so the user did not see it. Placing it outside the viewing area would cause problems, so the obvious answer was to place it right in the middle. At first though, this sounds like it would mess up the UI, but if it is placed at the back behind a rectangle that matches the background colour, no one will know. I have used this “trick” many times in Visio. Remember if you do this to set the background or fill to “{StaticResource PhoneBackgroundBrush}” so it is hidden in borth dark AND light themes.

The big problem I ran into is with how the tiles are handled. The user has full control of the tiles life / death, but there is no way to let the app know that the image file created in isolated storage is no longer needed if the tile is deleted. The only thing provided by the ActiveTile collection is the uri that the tile uses to run the app.  So deleting a tile will create an orphaned image. One solution is to provide a cookie crumb of information in the Uri and some backwards logic. Once deleted, you can not check the uri to find out which tile has been deleted, but you can scan the existing tiles and find out which images are active. The rest of the images in the list are the orphaned ones.

I had an extra wrinkle to the tile issue, the tiles I create for the banner app are identical except for the colours, so I could reuse the tiles. I chose to name the tiles after the two colours used in the tile, the background colour and the text colour. To keep things simple I used the hex values of the colours as the image names. One issue I did run in to was that converting the colours to hex values resulted in a string starting with “#” which was not appreciated by the system. I am not sure why. The tile was created and functioned properly, but the tile image was just a plain rectangle using the accent colour. Removing the “#” got around the problem.

Another issue is that you can not rely on the date stamp of the file in isolated storage, so this should be taken into account when determining the image file names.

Anyone need a banner app to send messages during a presentation or as a greeter board at the airport?

John Marshall… Visio MVP       Visio.MVPs.org

Written by johnvisiomvp

June 27, 2013 at 11:54 am