View Single Post
Old 08-12-2024, 02:21 PM   #11
E-Book lezer
Member
E-Book lezer began at the beginning.
 
Posts: 24
Karma: 10
Join Date: Aug 2024
Location: Netherlands
Device: Samsung Tablet Galaxy Tab A7 (Cantook)
Quote:
Originally Posted by chaley View Post

The template code is:
Code:
python:
def evaluate(book, context):
	import re
	nt = []
	for w in re.split(r'([ _.()])', book.get('title')):
		nt.append(w.capitalize())
	return ''.join(nt)
The r'([ _.()])' is the list of letters that separate words to be capitalized. This choice may not be the best for your library. You might want to add more letters. You could use r'(\W)', all non-alphabetic letters, but this might do the wrong thing with words like "_aaa" (aaa would not be capitalized) or "a.b" (b would not be capitalized). The choice depends on how much cleanup is required. Personally, I would use r'(\W)' and clean up the odd wrong title.

If you change the template you can test it on some books using the template editor before running it in Search & replace.[*]Press OK. Wait. Changing titles requires writing the disk, which can take some time.[*]Check the results. If they aren't what you want then restore the backup.[/LIST]
EDIT: This template uses the python title() function to "Return a titlecased version of the string where words start with an uppercase character and the remaining characters are lowercase." It does a better job in some cases but suffers from changing words like "isn't" to "Isn'T".
Code:
python:
def evaluate(book, context):
	return book.get('title').title()
Hello, maybe you want to help me too.
I do (I think) exactly what it says and still it gives me the wrong result. What am I doing wrong?
Attached Thumbnails
Click image for larger version

Name:	Hoofdletters hoe het is.jpg
Views:	673
Size:	309.3 KB
ID:	210139   Click image for larger version

Name:	Hoofdletters hoe ik het invul.jpg
Views:	683
Size:	237.6 KB
ID:	210140   Click image for larger version

Name:	Hoofdletters resultaat.jpg
Views:	629
Size:	58.3 KB
ID:	210141  
E-Book lezer is offline   Reply With Quote