Change String Case with Diacritical Support

This script will change a string to either all lowercase or all uppercase and supports the option of removing diacriticals and replacing with plain text.

OS version: Any

property letters_uc : (characters of "ABCDEFGHIJKLMNOPQRSTUVWXYZÆŒØ?")
property letters_lc : (characters of "abcdefghijklmnopqrstuvwxyzæœø?")
property letters_dia_uc : (characters of "ÁÀÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜŸ")
property letters_dia_lc : (characters of "áàâäãåçéèêëíìîïñóòôöõúùûüÿ")
property letters_nondia_uc : (characters of "AAAAAACEEEEIIIINOOOOOUUUUY")
property letters_nondia_lc : (characters of "aaaaaaceeeeiiiinooooouuuuy")

set the_string to "TestingÁÀÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜŸ"
set convert_case to "lower" --or "upper"
set strip_diacriticals to false --if true diacriticals will be removed and the plain text will be returned
return change_case(the_string, convert_case, strip_diacriticals)

on change_case(the_string, convert_case, strip_diacriticals)
	if strip_diacriticals = true then
		set letters_dia_uc_replace to letters_nondia_uc
		set letters_dia_lc_replace to letters_nondia_lc
	else
		set letters_dia_uc_replace to letters_dia_uc
		set letters_dia_lc_replace to letters_dia_lc
	end if
	if convert_case = "lower" then
		set search_chars to letters_uc & letters_dia_uc
		set replace_chars to letters_lc & letters_dia_lc_replace
	else
		set search_chars to letters_lc & letters_dia_lc
		set replace_chars to letters_uc & letters_dia_uc_replace
	end if
	set return_string to ""
	repeat with i from 1 to (count of characters of the_string)
		set string_char to (character i of the_string)
		if search_chars contains string_char then
			repeat with j from 1 to (count of search_chars)
				if (item j of search_chars) = string_char then
					set return_string to return_string & (item j of replace_chars)
					exit repeat
				end if
			end repeat
		else
			set return_string to return_string & string_char
		end if
	end repeat
	return return_string as string
end change_case