//usr/bin/env SRC=$0 DST=$TMPDIR/${app=`basename ${0%.mm}`}.app/Contents/MacOS/$app ARGS="$*" /bin/bash -c ' \
    mkdir -p $(dirname $DST) && clang++ $SRC -o $DST -fmodules -fcxx-modules && exec $DST $ARGS'; exit

@import AppKit;

int main()
{
    @autoreleasepool {
        [[NSApplication sharedApplication] setActivationPolicy:NSApplicationActivationPolicyRegular];
        [NSApp activateIgnoringOtherApps:YES];

        NSMenu *appMenu = [[NSMenu new] autorelease];
        [appMenu addItem:[[[NSMenuItem alloc] initWithTitle:@"Quit"
            action:@selector(terminate:) keyEquivalent:@"q"] autorelease]];
        NSMenuItem *appMenuItem = [[NSMenuItem new] autorelease];
        [appMenuItem setSubmenu:appMenu];
        NSApp.mainMenu = [[NSMenu new] autorelease];
        [NSApp.mainMenu addItem:appMenuItem];

        // ----- Test case starts here -----

        // Test by passing -AppleLanguages "(fr_FR)" on the command line e.g.

        NSMenu *editMenu = [[NSMenu new] autorelease];
        editMenu.title = @"Can be anything";
        NSMenuItem *editMenuItem = [[NSMenuItem new] autorelease];

        bool useLocalizedTitle = false;
        if (useLocalizedTitle) {
            // Either the title must be the name matching the current translation of the app
            NSBundle *appKit = [NSBundle bundleForClass:NSApplication.class];
            NSString *localizedEditMenuTitle = [appKit localizedStringForKey:@"Edit" value:nil table:@"InputManager"];
            NSLog(@"%@ %@", appKit, localizedEditMenuTitle);
            editMenuItem.title = localizedEditMenuTitle;
        } else {
            // Or the menu needs to have an item that AppKit recognizes as an edit-selector
            [editMenu addItem:[[[NSMenuItem alloc] initWithTitle:@"Can be anything, the selector is what matters"
                action:@selector(copy:) keyEquivalent:@""] autorelease]];
        }

        [editMenuItem setSubmenu:editMenu];
        [NSApp.mainMenu addItem:editMenuItem];

        // This is enough for AppKit to add the Emoji menu

        // But without any items in the menu, AppKit doesn't add the dictation entry.
        // A single entry is enough though though, and can be anything.
        [editMenu addItem:[[[NSMenuItem alloc] initWithTitle:@"Can be anything"
            action:@selector(canBeAnything:) keyEquivalent:@""] autorelease]];

        // ----- Test case ends here -----

        NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 500, 300)
            styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable
            backing:NSBackingStoreBuffered defer:YES];

        [window center];
        [window makeKeyAndOrderFront:nil];

        [NSApp run];
        return 0;
    }
}