Skip to content

Testing a Language File

Tim Kennedy edited this page Nov 1, 2023 · 9 revisions

Language Testing

Starting with Get My IP version 0.9.3, language contributors can test a language file prior to submitting a PR.

Benefits of testing

Testing allows you to check:

  • That the language strings are spelled correctly
  • That the language strings are right for the context in which they are used
  • That a string fits in the space provided, is aligned properly and any line breaks are in the correct position
  • That the language file is syntactically correct

How the language files are used

  • The application always loads the en-US file first. This file contains all the language strings available to the application. It is the base from which other language files are derived.
  • If a language other than en-US is selected in Language Settings, it will be loaded next.
    • These first two files are compiled into the application and are not accessible for changes.
  • If the 'Enable language testing' option in Language settings is enabled, the test language file is loaded last.
    • This file is located in the application folder. It is an XML file that can be edited. Only one language file at a time can be loaded for testing.

When the application needs a language string, it searches these files from last to first. This enables the application to always find the language string, even if it needs to fall back to the default in the en-US file. This behavior allows us to use the test language file to check one or a few strings.

How to test

  1. Start Get My IP and navigate to Language Setting.
  2. Click the 'Open App Folder' button on the bottom row. This will open the folder in File Explorer. Alternatively, you can press Ctrl-Shift-F.

GetMyIP_Open_App_Folder

  1. Open the file named Strings.test.xaml with your editor. I suggest using an editor that will provide syntax highlighting for XML files. Xaml files are just a type of XML file.
  2. The file will look much like this:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib">

    <!--
        =============================================================================================================================
         Use this file for language testing. Any number (or all) of the language strings for a single language can be in this file.
	 The application will need to be restarted after each change to this.
        =============================================================================================================================
    -->

	<sys:String x:Key="NavTitle_Settings">Settings - Language Test</sys:String>

</ResourceDictionary>
  1. Replace the provided string with the strings that are to be tested. Any number of strings can be added, from one line to the entire file.
  2. Keep in mind that the ResourceDictionary tags at the beginning and end of the file must remain as they are. Refer to the contribution topic if needed.
  3. After the strings have been added, save the file. The file name must be Strings.test.xaml. The application will not find the file if it is renamed or in another folder. Additionally, ensure that the line endings are CRLF.
  4. Once the file is saved, return to Get My IP and check the Enable language testing checkbox. The application will restart.

GetMyIP_Enable_Testing

  1. You should now see your language strings in Get My IP.
  2. Should you need to make additional changes; you will need to restart the application for the changes to take effect.

Log Messages

The application log will contain two messages that are relevant to language testing. The first message indicates that language testing has been enabled. The second will show how many strings were loaded from the test language file.

2023/10/31 16:42:39.33 INFO   Language testing enabled
2023/10/31 16:42:39.33 DEBUG  14 strings loaded from D:\blah\blah\Strings.test.xaml

Errors!

If there are errors, a message box will be shown. The language files are loaded before logging is available, so the message box will be the only source of an error message. The message box will contain the error message. In the following example, a line in the file was repeated, causing a duplicate key.

GetMyIP_Error

14. <sys:String x:Key="NavTitle_Settings">Settings - Language Test</sys:String>
15. <sys:String x:Key="NavTitle_Settings">Settings - Language Test</sys:String>

In the blue box, the message indicates the line number (15 in this case) and position of the error. In the red box, the message indicates that the key has already been added and the name of the key is 'NavTitle_Settings'.

What if?

What if a string doesn't fit in the space provided or is misaligned?

  • The application was written in English. The same word or phrase may be longer (or shorter) in other languages. I've tried to design for varying lengths of strings, but I may have overlooked something. Just open a translation issue and we'll work on it together. 😃

What if the original Strings.test.xaml gets deleted or becomes unusable?

  • You can copy the original file from the repository here on GitHub, you can copy the code block that appears after item 4 above, or you could just reinstall the application.

That's all

Pretty simple, right? 😂

Suggestions?

⭐ Feel free to suggest improvements to this page by starting or adding to a discussion.

Clone this wiki locally