Thanks everyone for the ideas. In my case I am not doing anything related to eras like the OP, but wanted to attach traits with LUA if possible which was part of the original question. My purpose is to unlock uniques from other civs/leaders for any player under certain circumstances. I am close to my desired behavior by attaching player modifiers, but attaching new traits would make it all simpler.
The remaining difficulty is with unique units that replace another unit. For now I am using a combination of MODIFIER_PLAYER_UNIT_BUILD_DISABLED and MODIFIER_PLAYER_ADJUST_VALID_UNIT_BUILD to disable the normal unit and enable the unique unit. This works for city build queue options, but there is still a problem with upgrading units. Units still upgrade to the disabled unit instead of the unique unit. For example, I was testing with Nubian Pitati Archer (enabling it for non-Nubian civs) - cities could build it and no longer had the option to build the regular archer. However, slingers still upgraded to the regular archer.
To fix the upgrade issue I am thinking of writing a hook for the UnitUpgraded event that will replace the upgraded unit with the correct unique unit. To the user I still want it to appear the same as other upgrades so the unit needs to inherit promotions, etc... Does anyone know if this is possible and perhaps some mod or Firaxis code that does similar? I was looking through the UnitPanel.lua. I can see there is UnitCommandTypes.UPGRADE but I am not sure what other parameters I need to pass to UnitManager.RequestCommand().
Unique buildings do not give me the same problems even though they replace existing things because the EFFECT_ADJUST_PLAYER_VALID_BUILDING takes the arguments BuildingType and BuildingTypeToReplace. As far as I know EFFECT_ADJUST_PLAYER_VALID_UNIT_BUILD only takes a UnitType.