public static function name_to_label($fieldName)
    {
        // Handle dot delimiters
        if (strpos($fieldName, '.') !== false) {
            $parts = explode('.', $fieldName);
            // Ensure that any letter following a dot is uppercased, so that the regex below can break it up
            // into words
            $label = implode(array_map('ucfirst', $parts));
        } else {
            $label = $fieldName;
        }

        // Replace any capital letter that is followed by a lowercase letter with a space, the lowercased
        // version of itself then the remaining lowercase letters.
        $labelWithSpaces = preg_replace_callback('/([A-Z])([a-z]+)/', function ($matches) {
            return ' ' . strtolower($matches[1]) . $matches[2];
        }, $label);

        // Add a space before any capital letter block that is at the end of the string
        $labelWithSpaces = preg_replace('/([a-z])([A-Z]+)$/', '$1 $2', $labelWithSpaces);

        // The first letter should be uppercase
        return ucfirst(trim($labelWithSpaces));
    }