How to Only Apply to Top Level Menu


How do I apply the following only to the top-level menu, for this will apply to sub-menus also. Thanks!

add_filter( 'trp_beautify_language_name', 'trpc_change_language_name', 10, 3 ); function trpc_change_language_name ($  name, $  code, $  english_or_native ){     if ( $  code == 'en_US' ){                // replace with the code of the language to change         return 'EN';     // replace with your desired language name     }     if ( $  code == 'nl_NL' ){                // replace with the code of the language to change         return 'NL';     // replace with your desired language name     }     if ( $  code == 'es_MX' ){                // replace with the code of the language to change         return 'ES';     // replace with your desired language name     }     return $  name; }