def _apply_rule_if_compat(self, phonetic, target, language_arg):
candidate = phonetic + target<EOL>if '<STR_LIT:[>' not in candidate:  <EOL><INDENT>return candidate<EOL><DEDENT>candidate = self._expand_alternates(candidate)<EOL>candidate_array = candidate.split('<STR_LIT:|>')<EOL>candidate = '<STR_LIT>'<EOL>found = False<EOL>for i in range(len(candidate_array)):<EOL><INDENT>this_candidate = candidate_array[i]<EOL>if language_arg != <NUM_LIT:1>:<EOL><INDENT>this_candidate = self._normalize_lang_attrs(<EOL>this_candidate + '<STR_LIT:[>' + str(language_arg) + '<STR_LIT:]>', False<EOL>)<EOL><DEDENT>if this_candidate != '<STR_LIT>':<EOL><INDENT>found = True<EOL>if candidate:<EOL><INDENT>candidate += '<STR_LIT:|>'<EOL><DEDENT>candidate += this_candidate<EOL><DEDENT><DEDENT>if not found:<EOL><INDENT>return None<EOL><DEDENT>if '<STR_LIT:|>' in candidate:<EOL><INDENT>candidate = '<STR_LIT:(>' + candidate + '<STR_LIT:)>'<EOL><DEDENT>return candidate<EOL>
Apply a phonetic regex if compatible.

        tests for compatible language rules

        to do so, apply the rule, expand the results, and detect alternatives
            with incompatible attributes

        then drop each alternative that has incompatible attributes and keep
            those that are compatible

        if there are no compatible alternatives left, return false

        otherwise return the compatible alternatives

        apply the rule

        Parameters
        ----------
        phonetic : str
            The Beider-Morse phonetic encoding (so far)
        target : str
            A proposed addition to the phonetic encoding
        language_arg : int
            An integer representing the target language of the phonetic
            encoding

        Returns
        -------
        str
            A candidate encoding