def get_locale_strings(path, prefix, middle, add_cr):
    """
    Returns a string created by converting an installer locale properties file
    into the format required by NSIS locale files.

    Parameters:
    path   - the path to the installer locale properties file to preprocess
    prefix - a string to prefix each line with
    middle - a string to insert between the name and value for each line
    add_cr - boolean for whether to add an NSIS carriage return before NSIS
             linefeeds when there isn't one already
    """
    output = ""
    fp = open(path, "r")
    for line in fp:
        line = line.strip()
        if line == "" or line[0] == "#":
            continue

        name, value = line.split("=", 1)
        value = value.strip() # trim whitespace from the start and end
        if value and value[-1] == "\"" and value[0] == "\"":
            value = value[1:-1] # remove " from the start and end

        if add_cr:
            value = value.replace("\\n", "\\r\\n") # prefix $\n with $\r
            value = value.replace("\\r\\r", "\\r") # replace $\r$\r with $\r

        value = value.replace("\"", "$\\\"") # prefix " with $\
        value = value.replace("\\r", "$\\r") # prefix \r with $
        value = value.replace("\\n", "$\\n") # prefix \n with $
        value = value.replace("\\t", "$\\t") # prefix \t with $

        output += prefix + name.strip() + middle + " \"" + value + "\"\n"
    fp.close()
    return output