WordPress is available in many languages, and Gravity Forms will localize some of its data based on the site's language.
This can sometimes cause issues with the auto-generated GraphQL schema, as GraphQL type and field names only allow a subset of ASCII alphanumeric characters.
If you run into issues with the GraphQL schema when using a non-English language, you can use the WPGraphQL core graphql_pre_format_name
filter to replace the problematic characters with a transliterated equivalent.
Note
The graphql_pre_format_name
filter is a core WPGraphQL filter is only available in WPGraphQL v1.17.0+.
Here's an example of how you can use the graphql_pre_format_name
filter to transliterate non-ASCII characters in the GraphQL schema:
add_filter( 'graphql_pre_format_name',
static function ( $formatted_name, string $original_name, string $replacement, string $regex ): string {
// Play nice with other filters.
$name_to_format = ! empty( $formatted_name ) ? $formatted_name : $original_name;
// Your character map
$char_map = [
'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'AE', 'Ç' => 'C',
'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I',
'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O',
'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Þ' => 'TH', 'ß' => 'ss',
'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c',
'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i',
'ð' => 'd', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o',
'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ý' => 'y', 'þ' => 'th', 'ÿ' => 'y',
];
// First transliterate the values.
$transliterated = str_replace( array_keys( $char_map ), array_values( $char_map ), $name_to_format );
// Then run the standard regex, since we're short-circuiting the standard `graphql_format_names()`.
return preg_replace( $regex, $replacement, $transliterated );
},
10,
4
);