Skip to content

Create standalone coldfusion file (cfml) that compares files and get missing labels

I´m working with Preside, that has some .properties extension files used for labing and translating the web content.

In our app we can have several with others where xxx is the name of the property and yy the language translation. The ones without yy are the default language.

Here an example for a default property file with his Spanish and French translations files and the labels add_usser, edit_user, delete_user:

    add_user    = Add website user
    edit_user   = Edit website user
    delete_user = Delete website user

    add_user    = Agregar usuario web
    edit_user   = Editar usuario web
    delete_user = Eliminar usuario web

    add_user    = Ajouter un utilisateur du site Web
    edit_user   = Modifier l utilisateur du site Web
    delete_user = Supprimer l utilisateur du site Web

What I need to do is to create a standalone cfml file that retreives all .properties files on the application and compare each default .properties file with his other translation files and show the missing labels of the compared file, if they exist.

So far what I can do is to retreive all the property files in a query with the name and path with directoryList and print each one of them.

propertiesFiles = directoryList("/application/i18n/", true, "query", "*.properties", "Directory", "all");

<cfoutput query="propertiesFiles"> &" "& propertiesFiles.Directory#

Can someone please tell me how to do the logic for looping and compare the labels of the default files with his translations using coldfusion? Or tell me an easy way to do it? Maybe embeding javascript?

Thanks in advance



Loop functions are one option. The files in question look like a bunch of lines separated by cairraige returns. Then, each line looks like a list separated by equal signs.

Also, there is an online library of user defined functions available for use. It includes a function called ListCompare, that can be applied to this situation.

The first step in my approach would be to write a function named getLabels that returns a list of labels from each file. It would

  1. read the file.
  2. Create a variable named labels with a value of an empty string.
  3. treat the resulting variable as a chr(10) delimited list. Loop through this list and on each iteration, use ListFirst(delimiter = "=") to get each label, and append that to the labels` variable.
  4. return the labels variable

The next step would be to use this function to get the labels from file Call this variable AllLabels.

Then start looping through the query created by your directoryList command. Use the getLabels function to get the labels from each file and the listCompare function to identify the missing labels.

User contributions licensed under: CC BY-SA
3 People found this is helpful