View Single Post
Old 06-10-2024, 11:41 AM   #7
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,497
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Bozana View Post
I'm not looking for title case. I'm looking for Proper Case. Title case leaves the "a" and "the" as lower case etc.., when converted. Whilst, Proper Case makes ALL first letters to Upper case, including "A" and "The" etc..

Title case:

He Lives in Edmonton, but Services all Over the Region, as a Electrican

Proper Case:

He Lives In Edmonton, But Services All Over The Region, As A Electrican


I already know that trick with Title Case that you've showed... I'm chasing Proper Case...

Thank you anyway.
You can do this with Bulk metadata edit / Search & replace using "template" as the source.
  1. Backup your library in case things go pear shaped.
  2. Select all the books you want to change.
  3. Go to Bulk metadata edit, search & replace tab. Make it look like the following:
    Click image for larger version

Name:	Clipboard02.jpg
Views:	1580
Size:	134.4 KB
ID:	208788

    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.
  4. Press OK. Wait. Changing titles requires writing the disk, which can take some time.
  5. Check the results. If they aren't what you want then restore the backup.

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()

Last edited by chaley; 06-10-2024 at 12:12 PM.
chaley is offline   Reply With Quote