Skip to main content
Participant
September 3, 2020
Question

how to change language both document and the styles

  • September 3, 2020
  • 1 reply
  • 284 views

I tried to  find and change wrong language(s) in the document with new one.

most of the paragraph ranges contain  overrides so at the beginning language in the styles should be replaced to new one and then overrided context.

as far as I figure out the following code does not change the language

 

	////find
	//IFindChangeOptions::SearchMode searchMode = IFindChangeOptions::kTextSearch;
	InterfacePtr<ICommand> formatCmd(CmdUtils::CreateCommand(kFindChangeFormatCmdBoss));
	if (formatCmd == nil)
		return;
	
	InterfacePtr<IFindChangeFormatCmdData> formatCmdData(formatCmd, IID_IFINDCHANGEFORMATCMDDATA);
	if (formatCmdData == nil)
		return;
	
	// old
	InterfacePtr<IAttrReport> oldLanguage(TextAttrHelper::CreateTextAttribute<ITextAttrUID, ITextAttrUID::ValueType>(kTextAttrLanguageBoss, langUID));
	if (oldLanguage == nil){
			return;
	}
	// new
	InterfacePtr<IAttrReport> destLanguage(TextAttrHelper::CreateTextAttribute<ITextAttrUID, ITextAttrUID::ValueType>(kTextAttrLanguageBoss, destLangUID));
	if (destLanguage == nil){
			return;
	}
	
	
	AttributeBossList findAttributeList;
	findAttributeList.ApplyAttribute(oldLanguage);
	AttributeBossList changeAttributeList;
	changeAttributeList.ApplyAttribute(destLanguage);
	
	formatCmdData->ClearFindAttributeBossList();
	formatCmdData->ApplyFindAttributeBossList(&findAttributeList);
	formatCmdData->ApplyChangeAttributeBossList(&changeAttributeList);
	
	ErrorCode status =  CmdUtils::ProcessCommand( formatCmd ) ;
	if (status != kSuccess) {
		return;
	}

	// search
	InterfacePtr<IFindChangeService> findChangeService((IFindChangeService*)::CreateObject(kFindChangeServiceBoss, IID_IFINDCHANGSERVICE));
	if (!findChangeService)
	{
		return;
	}
	auto db = ::GetUIDRef(document).GetDataBase();
	auto foundObject = ::UIDRef(db, langUID);
	///
	IFindChangeService::FindChangeResult findStatus = findChangeService->SearchObject(foundObject, kTrue /*!fInitialized*/);
	findChangeService->ReplaceObject();

 

This topic has been closed for replies.

1 reply

Participant
September 8, 2020

Dear Mike;

Thanks for your reply. I can make it by using javascript.

I have been developing a tool with c++ plug-in sdk. I can change the styles in document but can not change the language overrides on context.