Replace Text without loosing marks

I’m trying to replace combinations of letters with different letters (a+b → letter from other language).

Rule to translate on every transaction.

new InputRule(/(.*)/i,  (state, match, start, end) => {
      if (!match[0]) {
        return null;

      let tr ='NewTranslateWord', {word: match[0], start, end})       
      return tr;                                      

Plugin that replaces text.

import { Plugin, PluginKey } from 'prosemirror-state';

// replaces combinations of letters with letters in other language.
import { Translate } from './Utils';

const Languages = () => { 
  return new Plugin({
    key: new PluginKey( 'Translate'),  
    state: {
      init() {
        return { newWord : {} };
      apply(tr, state) {
        let newWordObject = tr.getMeta('NewTranslateWord') 
          let newState = newWordObject;
          return newState
        return {}     
    view: (view) => {
      return {
        update: (view, prevState) => {
          let newWordObject = view.state.Translate$;
            const {start, end} = newWordObject;
            let translatedString = Translate(newWordObject.word);
            view.dispatch(, start, end));
  'NewTranslateWord', {})       
            return true;

The problem with this plugin is, we are loosing marks (like bold, strike etc…) after every transaction. How do we keep the marks but just keep replacing the letters.

Are you trying to synchronously replace written text? That input rule seems to be blocking all input and replacing it with transactions that just have a meta property. I don’t think this is a reasonable way to do this (it seems like it’d prevent the user from typing at all). Also, firing additional transactions in a view plugin update method is a bad idea. Why does this need to go through a plugin? Wouldn’t it make more sense to immediately have the input rule create the appropriate transaction? Or even just directly register an input handler and avoid the input rule mechanism (which doesn’t seem helpful here).

Yes, I’m trying to synchronously replace the text.

the reason that I was taking every input (.*) because, the [a-zA-Z] letter that needs to be translated also depends on the immediate previous letter which is in other language.

I removed the plugin and trying to do this with inputRule. I agree that using (.*) in input rules is not good idea and because of it we are loosing the marks. But what can be a better input rule so that we can replace the text without loosing marks?