Firstly, I apologise if this was already asked. I’m not familiar with this website and the search seems quite glitchy.

Anyway, I’m trying to make a generator that will (amongst other things) create a basic Chinese ‘name’ in pinyin. Without tones is no issue. With tones, well, there’s a problem.

I can get all lowercase outputs just fine, and when the first letter is not accented, its also just fine. But if the first is accented, the output skips the accented letter and then capitalizes the SECOND letter.

For example,

tè áobǎ

Becomes this:

Tè áObǎ

When I actually want this:

Tè Áobǎ

I’m sure there is probably some fancy pants way to check if a letter is the first in the word and then substitute for the right letter, but, I am new to perchance, and my current searching hasn’t yielded any results on how this could be done.

Something like checking the first letter of the sentence case against a list of symbols, then using the substitute? (I’m not a coder, and I don’t know how to do this!)

my current code, barely worth even sharing:

output = [sentence]

sentence
  [pinyin.sentenceCase] [pinyin.sentenceCase][pinyin]
  • VioneT@lemmy.worldM
    link
    fedilink
    English
    arrow-up
    2
    ·
    3 months ago

    Ah, .sentenceCase is used to only capitalize the 1st letter of the sentence. You might want to use .titleCase to capitalize each word.

    • cass24@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      3 months ago

      sksksk something so simple-- Thank you so much! It is working as intended now. ♥

  • wthit56@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    3 months ago

    It seems to be working as expected, for me…

    "tè áobǎ".sentenceCase -> Tè áobǎ
    "tè áobǎ".titleCase -> Tè Áobǎ
    

    And using your code (plus pinyin = tè áobǎ) also seems to work as you expected.

    If it’s still not working correctly, maybe give us a link to the generator you’re working on (remember to save first), so that we can see it ourselves.