How can you customize the keyboard layout / shortcuts? I've recently migrated from Ubuntu to Mac, but one of the features that I'm lacking most is the keyboard layout for alternative languages. I don't like to switch keyboard layouts all the time, yet at the same time I like to write using accents and diacritics, as needed in each language (Romanian, French, German, etc.). 

The Romanian keyboard layout provided on Linux offers a very nice "compatibility variant", specially for programmers. Basically it's identical to the English one, but holding down the right Alt (level 3) key gives you the Romanian special characters:



How can I have a similar functionality?  

Can I at least customize it along these lines:


⌥ + a » ă
⌥ + s » ș
⌥ + t » ț




PS: I am aware of the Accent Menu and it's limitations.
Although it isn't exactly what you asked for, one possible solution is to use the built-in ability to rapidly switch Input Sources (aka keyboard layouts). To make this function useable, you'll need to do a little setup.

Open System Preferences: Keyboard and select the Keyboard Pane. Check the option to Show Keyboard &amp; Character Viewers in menu bar (1), then click on the Input Sources… button (2).



The Language and Text preference pane will open to the Input Sources tab. Select the input sources (3) you want to access on a regular basis. Fewer is better, remember you can always return to this tab and change your selections. When you've made your choices click on the Keyboard Shortcuts… button (4).



The Keyboard preferences pane will open to the Keyboard Shortcuts tab. Select Keyboard and Text Input from the column on the left (5). Then check the options to enable the keyboard shortcuts to navigate between input sources. (6).



If you stay with the default shortcuts, they will conflict with  the default Spotlight shortcuts. Select Spotlight from the column on the left, and either deactivate or change the keyboard shortcut assigned to the Spotlight functions.



Now when you need to type a special character, use the hotkey to select the appropriate Input Source and use Lion's long hold function to bring up the choices for each character. 

I am currently using Romanian as my Input Source . I know this because it's displayed in the Keyboard and Character Viewers menu item. A long press on a provides:



Once I've typed the Romanian character, I can use the keyboard shortcut to return to the U.S. input source.