views:

52

answers:

3

Is there a way of synchronizing changes made in a html file only in some areas? leaving the other elements intact.

Lets say I have these 2 files:

hello-world-english.html:

<div>
<p>Hello World</p>
</div>

hello-world-spanish.html:

<div>
<p>Hola Mundo</p>
</div>

And I make the following change to the first one (hello-world-english.html):

<div id=new-div">

<div>

<h2 id="new-header-2">
</h2>

<p>Hello World</p>
</div>

<div>

Then I want the second one to synchronize the changes but leaving what's inside the <p> tag intact:

<div id=new-div">

<div>

<h2 id="new-header-2">
</h2>

<p>Hola Mundo</p>
</div>

<div>

P S :

I'm using Vim!

+1  A: 

You could use <iframe> to separate what you want to keep syncronized in different files, for example:

hello-world.html:
<div id="new-div">
<div>
<h2 id="new-header-2">
</h2>
</div>
</div>

'

hello-world-english.html:
<iframe src="hello-world.html"></iframe>
<p>Hello World</p>

'

hello-world-spanish.html:
<iframe src="hello-world.html"></iframe>
<p>Hola Mundo</p>

But that'd be a problem if you want the unmodified data to be, for example, inside one of those <div>. Alternatively, you could write a generator that'd take two files: hello-world.html and a list of the parts you want to keep separated. The trick here is to use a special marker, such as @ (or any other rarely used character), and replace it with one of the items in the list, which would be fairly trivial. Just regenerate when either hello-world.html or the list get updated, and you're all set.

Or rather not. I think the problem is already solved by someone with better experience than me. Google is you friend ;).

MeDiCS
A: 

Short answer: No.

Longer answer: it really depends on what changes you are making to the file. Two possibilities come to mind:

1) make the changes to one file and run it through your version control diff (you are using version control, aren't you?) to get a patch file. Then apply the patch file to the other HTML file.

2) write a vim script with a series of edit commands that make the changes you want, and then open each file in vim and :source the script.

Both if these may fail or make unexpected changes if they hit differences between the HTML files that they are not expecting.

Better answer: Maintaining two version of the html file with different languages is a really bad idea and will not scale (what if you want to add a third language? A fourth? A tenth?). I suggest having a template file with placeholders for all the user-visible text, and a script (in Python, Ruby or whatever you are comfortable with) that replaces the placeholders with text from a language-specific conversion table. Then adding a new language is simply a matter of writing a new conversion table, and you can make whatever changes you want to the template and regenerate the HTML for every language.

Dave Kirby
A: 
:h diff

Have vim display the differences between the two files, and use dp and do to update the part you wish to.

Luc Hermitte