Parsing a Simple Text File |
SolutionOpen the rule in the Catalyst UIOpen Tools | Options | ezParse in Catalyst and you will see the form in the screen below. On this form add a text parse rule and open the rule by selecting it and then pressing the 'Edit Methods' button which you can see highlighted in the screenshot below.
Load the file you wish to parseYou need to navigate to the file that you wish to parse and then select the Preview button so that you can see the internal contents of the file while you are creating the parse rule. You will then see the internal contents in the bottom left of the parse rule window as seen in the screenshot below.
Deciding on the localizable content in the fileThe first step in parsing localizable content out of a text parse rule is to decide on the start point of the string that you wish to translate. In the text file above I have identified that the text I wish to insert into Catalyst to be localized, is about half way through each line after the tab. The next thing to decide on is where in the file the text that you wish to insert into Catalyst for localization ends. In the file in the screenshot above I have identified that the text I wish to localize ends at the end of each line. Parsing the text file by creating a parse ruleTo parse this text file I need to tell Catalyst to start the string to be parsed after the tab and end it at the end of the line. To tell Catalyst where to start in the 'Translatable Strings' section of the window add \t. This tells Catalyst to insert text after the tab in the file. The \t in the rule is taken from regular expression and this is the Syntax that is used to create all text parsing rules. If you wish to see a list of regular expression commands that can be used you should left click on a section of the translatable strings and then right click. This will give you a drop down menu of these commands. The next part of the rule is to tell Catalyst that you wish to end the text inserted into Catalyst at the end of the line. In the screenshot below you can see that I did this using $ to signify the end of the line. Another way of telling Catalyst to do this would be to use \r\n as the end of line signifier. The final part of this parse rule is to tell Catalyst that we do not want to insert the tags into Catalyst for translation. This is done by selecting 'Hide' under Show Tags. If 'Show' was selected then there would be a tab inserted into Catalyst before every string to be translated and this would not be a good parse rule.
Click here to download the txt file that was used in this FAQ.
Products or Versions Affected
|